2010-12-08 95 views
3

在uTorrent 2.2中,当选择树视图节点时,该节点具有类似的按钮外观。它使.NET的treeview控件看起来对我来说太不合适了。现在我知道utorrent是用C++编写的,但是有谁知道他们是如何做到这一点的,或者是否有人知道那里的图书馆足够了?TreeView控件类似于utorrent的控件

alt text

回答

4

它与Win7的 “资源管理器” 视觉应用的样式一个标准的Windows TreeView控件。通过更改控件的主题,您可以轻松地在自己的程序中获得一个。为您的项目添加一个新类并粘贴下面显示的代码。编译。将新的控件从工具箱的顶部拖放到表单上。

using System; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 

class MyTreeView : TreeView { 
    protected override void OnHandleCreated(EventArgs e) { 
     if (Environment.OSVersion.Version.Major >= 6) { 
      SetWindowTheme(this.Handle, "Explorer", null); 
     } 
     base.OnHandleCreated(e); 
    } 
    [DllImportAttribute("uxtheme.dll", CharSet = CharSet.Auto)] 
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist); 
} 

除非使用WindowsFormHost类,否则这不是WPF的直接可能。