给 C# 控件换肤?

发布于 2024-10-14 15:18:59 字数 80 浏览 1 评论 0原文


有没有办法为 C# 控件制作新皮肤?
例如,我想要一个与默认列表视图具有相同功能的列表视图 但外观完全不同。
谢谢 :)

Is there a way to make a new skin to a C# control?
for example, I want to have a listview with the same functionality of the default one
but with a completely different look.
thanks :)

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

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

发布评论

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

评论(5

ζ澈沫 2024-10-21 15:18:59

取决于你的图书馆。

获胜形式:乏味且很难做到。完成单个控件的造型后,您的头上将没有头发。

Wpf:Wpf 正是为此而构建的(当然,还有许多其他令人惊奇的事情)。这个页面可能会对您有很大帮助。

如果您想完全为您的应用程序换肤,我建议您学习并使用 WPF。我也这么做了,这真是太棒了,不仅仅是可定制性,还有一般的一切。它是一个很棒的平台,但由于它需要 DirectX 和更多资源,因此它的可移植性较差。

Depends on your library.

Win Forms: tedious and really hard to do. You will have no hair on your head after you are finished with styling one single control.

Wpf: Wpf is build for exactly that (and of course, many other amazing things). This page might help you alot.

If you want to skin your application entirely, I'd advise you to learn and use WPF. I did it is as well and it is amazing, not just the customizability, but everything in general. It is a great platform, but as it needs DirectX and more resources, it is not as portable.

千笙结 2024-10-21 15:18:59

不过,如果您使用 Windows.Forms 并希望更改控件的外观,那么这会有点困难。

您必须从控件创建派生类并重写 OnPaint 和 OnPaintBackground 事件并实现您自己的代码。

Still, if you are using Windows.Forms and wish to change the look of your controls than it will be a bit tougher.

You will have to create a derived class from the control and override the OnPaint and OnPaintBackground events and implement your own code.

茶底世界 2024-10-21 15:18:59

是的,有了 WPF,一切皆有可能。但如果您仅习惯 Windows 窗体,请记住 WPF 是一项新技术,具有新概念,需要一些时间来学习。

Yes, with WPF everything is possible. But if you're used to Windows Forms only, keep in mind that WPF is a new technology with new concepts that take some time to learn.

十二 2024-10-21 15:18:59

正如Femaref所说,WPF中有很多可能性,但在WinForms中却相当困难。

如果您想比他链接的页面更进一步(它仅涵盖样式),您可能会对同一页面侧边栏中的“模板和样式”点感兴趣: 模板和样式 并在模板部分中: 模板。使用模板,您可以完成样式无法完成的大部分操作。一个非常基本的示例(您几乎可以在每个有关模板的教程中找到)是椭圆形按钮。此外,您还可以使用触发器重新定义其他内容,例如鼠标悬停和鼠标单击的外观。

希望有帮助;)

As Femaref says, there are many possibilities in WPF, but it is rather difficult in WinForms.

If you want to go a bit further than the page linked by him does (it only covers styles), you may be interested in the point "templates and styles" in the sidebar of the same page: templates and styles and in the templates part there: templates. With templates, u can do most of the things you cannot do with styles. A quite basic example (that u will find in almost every tutorial about templates) is an elliptic button. Additionally, you can also redefine other things, e.g. the mouse over and mouse click appearence by using triggers.

Hope that helps ;)

俯瞰星空 2024-10-21 15:18:59

我以前也走过这条路,但它并不漂亮。最后我没有重新设计控件。我们遇到了 WinForms 树视图的问题。那是另一个故事了。

在 WinForms 中,是的,您可以为要编辑的控件创建派生版本。并重写了OnPaint和相关的Paint方法。对于树形视图来说,这是一场噩梦,所以最终没有这样做。除非您有从头开始绘制控件的经验,否则我不会考虑此选项。

如果您使用 WPF,则控件全部由视觉元素组成会更容易,并且更改它们也更容易。 WPF 的控件较少,并且依赖开发人员根据自己的需要进行编辑。就我个人而言,我想要更基本的 WPF 控件,例如 WinForms,但那又是另一个故事了。

另外 2 个选项是,从头开始一个全新的控件,或者在网上找到您喜欢的控件的外观并购买。许多网站出售定制的 .net 控件。

I've gone down this route before, and its not pretty. In the end I didnt reskin the control. We had an issue with a WinForms treeview. Thats a tale for another time.

In WinForms, then yes you make a derived version for the control you want to edit. And overright the OnPaint and relevant Paint methods. For the treeview this was a nightmare so didn't do it in the end. Unless your experienced in drawing controls from scratch I would not consider this option.

If your in WPF, its much easier the controls are all made of visual elements, and is much easier to change them. WPF has fewer controls and relying on the developer editing them for there own need. Personally I want more basic WPF controls like WinForms, but again thats another tale.

The other 2 options are, start a brand new control from scratch, or find the look of a control you like online and purchase it. Many websites sell custom made .net controls.

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