#region 更改失去焦点选中节点的颜色
private void Tree_Organize_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.FillRectangle(Brushes.White, e.Node.Bounds);
if (e.State == TreeNodeStates.Selected)//选中的失去焦点的节点
{
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(e.Node.Bounds.Left - 1, e.Node.Bounds.Top, e.Node.Bounds.Width - 2, e.Node.Bounds.Height)); //背景
e.Graphics.DrawString(e.Node.Text, Tree_Organize.Font, Brushes.White,e.Bounds.Location.X,e.Bounds.Location.Y);//字体
}
else
{
e.DrawDefault = true;
}
}
#endregion
在窗体的LODE事件中加上:
Tree_Organize.HideSelection = false;
Tree_Organize.DrawMode = TreeViewDrawMode.OwnerDrawText;
更改树视图选中节点颜色
本文介绍如何使用C#编程语言自定义Windows窗体应用程序中的树视图(TreeView)控件,通过OwnerDrawText模式来改变失去焦点时选中节点的显示样式,包括背景色和字体颜色。
1703

被折叠的 条评论
为什么被折叠?



