如何在.NET中创建非OwnerDraw按钮?

发布于 2024-07-10 02:10:25 字数 277 浏览 15 评论 0原文

我正在为一个软件创建一个插件,为我创建的表单添加皮肤。 但是,按钮不是基于它们的皮肤,而是显示标准的灰色按钮。 在软件论坛上询问时,我发现 .NET 表单控件是所有者绘制的,因此我的按钮不会以正确的样式重新绘制,而是创建一个非所有者绘制按钮。

system.windows.forms 命名空间中的所有控件似乎都是所有者绘制的。

那么如何在 .NET 中创建标准的 C++ PUSHBUTTON?

目前正在使用 C# 进行编码(如果有帮助的话)。

谢谢

I'm creating a plugin to a software that skins the form I created. However, the button are not skin based on them and a standard gray button is shown. Asking on the software forum pointed me that .NET forms control are owner-draw and therefor my button won't redraw with the correct style instead of creating a non ownerdraw button.

All controls in the system.windows.forms namespace seem to be ownerdraw.

So how can I create a standar C++ PUSHBUTTON in .NET?

Currently codding in C# if that helps.

Thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

剩一世无双 2024-07-17 02:10:25

标准是默认设置,因此没有重新设计。 当设置为平面时,我得到背景颜色和前景色,但失去了圆角端悬停效果,表明控件没有重新设计外观,仅应用了颜色样式。 扁平是唯一不是灰色的版本,但我失去了一些按钮功能(悬停、圆角)

Standard was the default and therefor wasn't reskinned. When setted to flat, I get a background color and a foreground color, but lose the round corner end the hover effect suggesting that the control is not reskinned and just color style is applyed. Flat is the only version not grey, but I lose some of button feature (hover, round corner)

九命猫 2024-07-17 02:10:25

Windows.Forms 中的控件不是所有者绘制的,而是系统绘制的。 这就是 Windows 默认绘制它们的方式,无论是按钮、文本框还是其他东西。 您可以通过指定控件应该是所有者绘制(即:您负责绘制它)来覆盖绘图 - 有些控件支持这一点,其中一些控件甚至具有更细的粒度(请参阅 ListView),或者您可以在任何 Control 后代的 OnPaint 事件中完全覆盖绘画。

你的问题相当令人困惑 - 据我所知,你在插件中创建的按钮没有皮肤。 显然,您需要告诉这个皮肤框架来绘制这些按钮。 可能有或应该有一些组件,您可以将其放置到您调用的插件表单或方法上,这些组件会将蒙皮绘制例程注入到您的插件中。

The controls in Windows.Forms are not owner-drawn, but rather system-drawn. This is how Windows paints them by default, be it a Button, TextBox or what else. You can override the drawing either by specifying that the control should be owner-drawn (that is: you are responsible for drawing it) - some controls support that, a couple of them even with a finer granularity (see ListView), or you can override the painting completely in OnPaint event of any Control descendant.

Your question is rather confusing - as I understand the buttons you create in your plug-in are not skinned. Obviously what you need is to tell this skinning framework to paint these buttons. There probably is or should be some component that you drop onto the plug-in form or method you call that will inject the skinning painting routines into your plug-in.

眼前雾蒙蒙 2024-07-17 02:10:25

听起来您想将按钮的 FlatStyle 属性设置为 FlatStyle.System。 默认情况下,Windows 窗体按钮确实是所有者在 WinAPI 级别绘制的,并且由框架绘制。

It sounds like you want to set the FlatStyle property of your button to FlatStyle.System. Windows Forms buttons are indeed, by default, owner draw at the WinAPI level, and are drawn by the framework.

羁〃客ぐ 2024-07-17 02:10:25

您是否尝试过将 FlatStyle 设置为其他值,例如 FlatPopup,只是为了看看这是否会阻止它被换肤?

另外设置 Flaststyle = Standard (相对于系统)可能会解决您的问题

Have you tried setting the FlatStyle to another value, such as Flat or Popup, just to see if that stops it being skinned?

also setting Flaststyle = Standard (as opposed to system) might solve your problem

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