本文介绍了如何在树视图中更改所选节点的背景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当winform应用程序在树视图中加载第一行的单元格时有蓝色背景颜色。

如何更改它的颜色?

提前谢谢



我尝试过:



Afterselected事件,Beforeselected事件但它没有工作

Hi,
When the winform application loads first row's cell in treeview has blue backcolor.
How do I change the color of it?
Thank you in advance

What I have tried:

Afterselected event,Beforeselected event but it didn't work

推荐答案

private void Form1_Load(object sender, EventArgs e)
       {
           treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;
       }


       SolidBrush greenBrush = new SolidBrush(Color.Green);

       private void treeView1_drawNode(object sender, DrawTreeNodeEventArgs e)
       {
           if (e.Node.IsSelected)
           {
               if (treeView1.Focused)
                   e.Graphics.FillRectangle(greenBrush, e.Bounds);
           }
           else
               e.Graphics.FillRectangle(Brushes.White, e.Bounds);

           TextRenderer.DrawText(e.Graphics,    e.Node.Text,  e.Node.TreeView.Font,  e.Node.Bounds,  e.Node.ForeColor);
       }


这篇关于如何在树视图中更改所选节点的背景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 00:58