![Trees](https://i.stack.imgur.com/QJ5b8.png)
在 .NET 中使用 TreeView 组件时,我看到了左侧树的外观。
如何为我的 .NET TreeView 获得正确的树外观(Windows Native Look)?
我特别想要得到的是“三角形”节点手柄和蓝色“气泡”选择方块。
您需要 P/Invoke 才能调用SetWindowTheme传递树的窗口句柄并使用“explorer”作为主题。
将以下代码粘贴到项目中的新类中,编译并使用此自定义控件而不是内置控件TreeView
控制。
C#:
public class NativeTreeView : System.Windows.Forms.TreeView
{
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
private extern static int SetWindowTheme(IntPtr hWnd, string pszSubAppName,
string pszSubIdList);
protected override void CreateHandle()
{
base.CreateHandle();
SetWindowTheme(this.Handle, "explorer", null);
}
}
VB.NET:
Public Class NativeTreeView : Inherits TreeView
Private Declare Unicode Function SetWindowTheme Lib "uxtheme.dll"
(hWnd As IntPtr, pszSubAppName As String, pszSubIdList As String) As Integer
Protected Overrides Sub CreateHandle()
MyBase.CreateHandle()
SetWindowTheme(Me.Handle, "Explorer", Nothing)
End Sub
End Class
请注意,这个技巧对于ListView
控制。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)