Winforms 中的菜单类似于文件夹资源管理器菜单
如何在 winforms 中创建一个菜单,该菜单与我们浏览任何文件夹时 Windows 资源管理器左侧框架上显示的菜单完全相似。菜单包含出现的树节点和根节点。单击 + & 即可消失- 符号。
How to create a menu in winforms which totally resembles the menu which appears on Left Hand Frame in Windows Explorer when we Explore any folder. The menu contains tree nodes and root nodes which appear & disappear by clicking on the + & - symbols.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,这不是菜单,而是树视图。您可以使用 WinForms 树视图,但开箱后它看起来与 Explorer 树视图并不完全相同。您需要应用资源管理器窗口主题。
您需要 P/Invoke 来调用
SetWindowTheme
传递树的窗口句柄并使用“explorer”作为主题。将以下代码粘贴到项目中的新类中,编译并使用此自定义控件而不是内置
TreeView
控件。请注意,此技巧对于
ListView
控件的工作方式也完全相同。Well, that's not a menu, it's a tree view. You can use the WinForms tree view, but out of the box it won't look exactly like the Explorer tree view. You need to apply the Explorer window theme.
You need to P/Invoke to call
SetWindowTheme
passing the window handle of the tree and use "explorer" as the theme.Paste the following code into a new class in your project, compile, and use this custom control instead of the built-in
TreeView
control.Note that this trick also works exactly the same way for the
ListView
control.您可以在 WinForms 树视图中拥有多个“根”节点:
它们可以是带有子节点的完整节点,而不是上面的文本。
You can have multiple 'root' nodes in a WinForms treeview:
Instead of text above, they could be full nodes w/ children.