如何获得Windows自带的外观为.NET的TreeView? [英] How to get Windows native look for the .NET TreeView?
问题描述
当在.NET中使用TreeView的成分,我得到了左树的样子。 我怎样才能得到正确的树(Windows本地查找)对我的.NET TreeView控件的外观?
When using the TreeView component in .NET, I get the look of the left tree. How can I get the look of the right tree (Windows Native Look) for my .NET TreeView?
我特别希望得到的是三角节点处理和蓝色的泡泡选择方。
What I especially want to get is the "triangle" node handles and the blue "bubble" selection square.
推荐答案
您需要的P / Invoke来调用的 SetWindowTheme > <$ C $ 传递树的窗口句柄,并使用资源管理器为主题。
You need to P/Invoke to call SetWindowTheme
passing the window handle of the tree and use "explorer" as the theme.
粘贴以下code到一个新的类在你的项目中,编译,并使用此自定义的控制,而不是内置的的TreeView
控制。
Paste the following code into a new class in your project, compile, and use this custom control instead of the built-in TreeView
control.
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
控制。
Note that this trick also works exactly the same way for the ListView
control.
这篇关于如何获得Windows自带的外观为.NET的TreeView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!