你的位置:首页 > ASP.net教程

[ASP.net教程]Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012


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.Blue, new Rectangle(e.Node.Bounds.Left, e.Node.Bounds.Top, e.Node.Bounds.Width, e.Node.Bounds.Height));//背景色为蓝色
e.Graphics.DrawString(e.Node.Text, tVtypeList.Font, Brushes.White, e.Bounds);
//字体为白色
}
else
{
e.DrawDefault = true;
}
}
分享: