如何在树视图中更改所选节点的背景色? [英] How do I change backcolor of selected node in treeview?

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

问题描述



当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

推荐答案

试试这个

你必须改变 DrawMode 正常 OwnerDrawText 并更改中的颜色drawNode 活动



Try this
You have to Change the DrawMode from Normal to OwnerDrawText and Change the color in drawNode event

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);
       }


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆