c#中treeVIew怎么去掉點(diǎn)擊變背景色

小億
123
2024-05-29 10:26:09

在C#中,可以通過(guò)自定義樹(shù)形控件的樣式來(lái)去掉點(diǎn)擊時(shí)的背景色。具體步驟如下:

  1. 創(chuàng)建一個(gè)自定義的樹(shù)形控件類(lèi),繼承自TreeView類(lèi)??梢悦麨镃ustomTreeView。
public class CustomTreeView : TreeView
{
    protected override void WndProc(ref Message m)
    {
        // 禁止控件繪制選定項(xiàng)背景
        if (m.Msg == 0x14) // WM_ERASEBKGND
        {
            m.Result = IntPtr.Zero;
        }
        else
        {
            base.WndProc(ref m);
        }
    }
}
  1. 在窗體中使用這個(gè)自定義的樹(shù)形控件。
CustomTreeView customTreeView1 = new CustomTreeView();

通過(guò)上述方式,可以去掉點(diǎn)擊樹(shù)形控件時(shí)的背景色變化。

0