在 Winforms TreeView 控件中切换 TreeNode 的 StateImage 和 IndexImage 的位置
我想知道是否可以在 Winforms TreeView 中将 StateImage 的位置与 TreeNode 的 IndexImage 的位置切换?
请参阅下图以获取说明。
第一个 TreeNode 有 stateImage,第二个没有。
我的目标是所有 IndexImage 都向左对齐,而 StateImage(如果有)则位于 IndexImage 的右侧。
生成的树看起来像这样:
我想我必须将树 DrawMode 设置为 OwnerDraw 并覆盖 OnPaint。我读了 此 msdn 链接,但是没有提到绘画图像。我真的不知道如何继续。我们将非常感谢您提供的任何帮助和代码(C# 或 VB.net)。
非常感谢
I would like to know if it is possible to switch the position of a StateImage with that of an IndexImage for a TreeNode in a Winforms TreeView?
Please refer to the image below for an illustration.
The first TreeNode has a stateImage and the second one doesn't.
My aim is for all IndexImages to align to the left and the StateImage (if any) to be to the right of the IndexImage.
The resulting tree would look something like:
I think i have to set the tree DrawMode to OwnerDraw and override OnPaint. I read this msdn link but nothing there was said about drawing images. I really don't know how to proceed. Any help and code you could provide (in C# or VB.net) will be very much appreciated.
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这需要自定义绘图。
然后你必须处理 DrawNode 事件。请参阅 TreeView。 DrawNode 事件
DrawNodeEventArgs 事件中的
DrawTreeNodeEventArgs
参数有一个图形对象,您可以使用它来绘制从图像到文本的任何内容。当然,一旦你定制了,你就负责绘制所有东西(不幸的是)。请参阅 VisualStyles关于获取正确的 TreeView 字形。
简单说明:
此示例缺少绘制树控件和选择状态的代码,但它显示了两个图像和节点文本。自定义绘制 TreeView 需要大量工作。
Yes, this would require custom drawing.
Then you have to handle the DrawNode event. See TreeView.DrawNode Event
The
DrawTreeNodeEventArgs
parameter in theDrawNode
event has a graphic object you can use to paint anything, from images to text.Of course, once you go custom, you are responsible for drawing everything (unfortunately). See VisualStyles in regards to getting the proper TreeView glyphs.
Simple illustration:
This example is missing code to draw the tree controls and the selection state, but it shows two images and the node text. Custom drawing TreeViews are a lot of work.