Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼
标签: winform treeview drawnode
Treeview控件--Name:tVtypeList
将tVtypeList的HideSelection属性设置为False,DrawMode属性设置为OwnerDrawText
将tVtypeList的DrawNode事件写为:
private void tVtypeList_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.FillRectangle(Brushes.White, e.Node.Bounds);
if (e.State == TreeNodeStates.Selected)//做判断
{
e.Graphics.FillRectangle(Brushes.DodgerBlue, new Rectangle(e.Node.Bounds.Left, e.Node.Bounds.Top, e.Node.Bounds.Width, e.Node.Bounds.Height));//背景色为蓝色
Rectangle retangle = e.Bounds;
retangle.Width = retangle.Width + 10;
e.Graphics.DrawString(e.Node.Text, treeView1.Font, Brushes.White, retangle);
//字体为白色
}
else
{
e.DrawDefault = true;
}
}
分享: