如何使用现有的 ToolStripRenderer 绘制托管的 NumericUpDown?
我有一个控件,它在 ToolStripControlHost
中托管 NumericUpDown
并公开 NumericUpDown
的属性。 从功能上来说,这很好,但是当它放置在 ToolStrip
上时,它在视觉上与其他 ToolStripItem
不相符。
我想使用 ToolStrip
现有的 ToolStripRenderer
以类似于也在 ToolStripComboBox
es 上的方式绘制控件控制。 我对创建自定义 ToolStripRenderer
来执行此操作不感兴趣,因为我希望使用该控件的其他人能够将其与他们选择的渲染器一起使用。
我尝试在托管控件类和托管控件类中重写 OnPaint
和 OnPaintBackground
,并使用渲染器的绘图方法,但我所能实现的就是拥有边缘周围未上漆的区域; 旋转按钮仍然以系统主题绘制。
如何使用现有的 ToolStripRenderer
绘制托管的 NumericUpDown
?
I have a control which hosts a NumericUpDown
in a ToolStripControlHost
and exposes the NumericUpDown
's properties. Functionally, that's fine, but when it's placed on a ToolStrip
it doesn't fit visually with the other ToolStripItem
s.
I'd like to use the ToolStrip
's existing ToolStripRenderer
to draw the control in a manner similar to the ToolStripComboBox
es that are also on the control. I'm not interested in creating a custom ToolStripRenderer
to do that, as I want others who use the control to be able to use it with whichever renderer they choose.
I've tried overriding OnPaint
and OnPaintBackground
in the hosting control class, and in the hosted control class, and using the renderer's drawing methods, but all I can achieve is to have an unpainted region around the edges; the spin buttons are still drawn with the system theme.
How do I paint a hosted NumericUpDown
using the existing ToolStripRenderer
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NumericUpDown 类实际上只是作为 GDI 一部分存在的公共控件类的包装。 底层公共控件将以两种方式之一绘制自身,具体取决于是否为应用程序启用了视觉样式。 要覆盖绘图,您需要自己执行所有绘图。 您无法告诉控件您只想覆盖按钮或边框。
自己完成所有绘图比听起来要困难得多。 抱歉,我无法提供一个简单的解决方案,但我认为没有一个简单的解决方案。
The NumericUpDown class is really just a wrapper around the common control class that exists as part of GDI. The underlying common control will draw itself in one of two ways depending on if visual styles are enabled for the application. To override the drawing you will need to perform all the drawing yourself. You cannot tell the control you want to only override the buttons or the border.
Performing all the drawing yourself is much harder than it sounds. Sorry I cannot offer an easy solution but I do not think there is an easy solution.