【Winfrom-TreeView】 跟随系统改变Style
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同样适用。