treeview选中节点深色显示
winform
还是一样的问题,如何点击treeview节点深色显示,以提示用户当前选择项,并且选中之后点击添加按钮,treeview Enable 为false,但之前深色仍然存在
小弟我是这样做的
加载事件
this.tvFcList.DrawMode = TreeViewDrawMode.OwnerDrawAll;
this.tvFcList.DrawNode += new DrawTreeNodeEventHandler(tvFcList_DrawNode);
void tvFcList_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if ((e.State & TreeNodeStates.Selected) != 0)
{
//演示为绿底白字
e.Graphics.FillRectangle(Brushes.Silver, e.Node.Bounds);
Font nodeFont = e.Node.NodeFont;
if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
//画刷坐标区域
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.Black, e.Node.Bounds.X, e.Node.Bounds.Y);
}
else
{
e.DrawDefault = true;
}
if ((e.State & TreeNodeStates.Focused) != 0)
{
using (Pen focusPen = new Pen(Color.Black))
{
//focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
//Rectangle focusBounds = e.Node.Bounds;
//focusBounds.Size = new Size(focusBounds.Width - 1,
//focusBounds.Height - 1);
//e.Graphics.DrawRectangle(focusPen, focusBounds);
}
}
这样做是可以深色显示并且enble为false时也显示,但点击节点的时候父节点前面+号一级showline的线条在点击节点消失了,请教高手怎么做,或者有什么更好 更简单的方法,不胜感激