在C#中,可以通過(guò)自定義樹(shù)形控件的樣式來(lái)去掉點(diǎn)擊時(shí)的背景色。具體步驟如下:
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);
}
}
}
CustomTreeView customTreeView1 = new CustomTreeView();
通過(guò)上述方式,可以去掉點(diǎn)擊樹(shù)形控件時(shí)的背景色變化。