如何使用现有的 ToolStripRenderer 绘制托管的 NumericUpDown?

发布于 2024-07-14 10:26:17 字数 634 浏览 5 评论 0原文

我有一个控件,它在 ToolStripControlHost 中托管 NumericUpDown 并公开 NumericUpDown 的属性。 从功能上来说,这很好,但是当它放置在 ToolStrip 上时,它在视觉上与其他 ToolStripItem 不相符。

我想使用 ToolStrip 现有的 ToolStripRenderer 以类似于也在 ToolStripComboBoxes 上的方式绘制控件控制。 我对创建自定义 ToolStripRenderer 来执行此操作不感兴趣,因为我希望使用该控件的其他人能够将其与他们选择的渲染器一起使用。

我尝试在托管控件类和托管控件类中重写 OnPaintOnPaintBackground ,并使用渲染器的绘图方法,但我所能实现的就是拥有边缘周围未上漆的区域; 旋转按钮仍然以系统主题绘制。

如何使用现有的 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 ToolStripItems.

I'd like to use the ToolStrip's existing ToolStripRenderer to draw the control in a manner similar to the ToolStripComboBoxes 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2024-07-21 10:26:17

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文