如何在关闭视觉样式的情况下绘制 UI 元素?
我有一个所有者绘制的控件,我需要在其中绘制树视图的展开框(“加/减”)。打开视觉样式后很容易,只需为适当的 VisualStyleElement 创建一个渲染器:
VisualStyleElement element = VisualStyleElement.TreeView.Glyph.Opened
VisualStyleRenderer renderer = new VisualStyleRenderer( element );
Size size = renderer.GetPartSize( graphics, ThemeSizeType.True );
...
renderer.DrawBackground( graphics, someRect );
当视觉样式关闭时是否可以实现类似的效果?我知道有一个 ControlPaint 类可以绘制整个控件,但是如何仅绘制(并获取其大小)TreeView 控件的一部分?
I have a owner drawn control where I need to draw the expand box ("plus/minus") of a treeview. With visual styles turned on it is easy, just create a renderer for the appropriate VisualStyleElement:
VisualStyleElement element = VisualStyleElement.TreeView.Glyph.Opened
VisualStyleRenderer renderer = new VisualStyleRenderer( element );
Size size = renderer.GetPartSize( graphics, ThemeSizeType.True );
...
renderer.DrawBackground( graphics, someRect );
Is it possible to achieve a similar effect when visual styles are off? I know there is a ControlPaint class which can draw entire controls, but how do I draw (and get the size of) just a part of the TreeView control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有 VisualStyles,我认为加减控件只是 DrawRectangle 和 DrawLine 方法调用。
矩形部分看起来像使用
SystemColors.Control
颜色,加/减部分看起来像SystemColors.ControlText
(或黑色)。Without VisualStyles, I think the plus minus controls are just DrawRectangle and DrawLine method calls.
The Rectangle part looks like it uses the
SystemColors.Control
color, and the Plus/Minus part looks likeSystemColors.ControlText
(or black).