简体   繁体   English

C# + 控件上的自定义图形?

[英]C# + Custom graphics on controls?

I was just wondering if there are ways of creating my own custom winforms controls?我只是想知道是否有办法创建我自己的自定义 winforms 控件? I've been plundering with Visual Studio 2008 now trying to do some c# apps.我一直在掠夺 Visual Studio 2008 现在试图做一些 c# 应用程序。 And the GUI end up looking terrible because of the standard winforms limitations.由于标准的 winforms 限制,GUI 最终看起来很糟糕。

And I noticed that I can add images to buttons for example, but ther's no hover effect.我注意到我可以向按钮添加图像,但没有悬停效果。 Or, the hover effect makes the whole button area gray.或者,悬停效果使整个按钮区域变灰。 I don't want any of that, I just want to either create my own graphics for the controls or find some free (opensource perhaps) controls that already exist.我不想要任何这些,我只想为控件创建我自己的图形或找到一些已经存在的免费(也许是开源)控件。

Any light on any of this, anyone?任何人都对此有任何了解吗? :) :)

You can write complete Winforms controls from scratch, doing all the painting and input processing yourself - you just create a class derived from 'Control' and get on with it.您可以从头开始编写完整的 Winforms 控件,自己完成所有绘制和输入处理 - 您只需创建一个派生自“Control”的类并继续使用它。

There's a fair bit to making a first-class control which integrates nicely with the VS designer, so people tend to derive their custom control from an existing control which has most of the behaviour they want.制作与 VS 设计器很好地集成的一流控件有一定的意义,因此人们倾向于从具有他们想要的大部分行为的现有控件中派生出自定义控件。

Here would be a good place to start: http://msdn.microsoft.com/en-us/library/6hws6h2t.aspx这里将是一个很好的起点: http : //msdn.microsoft.com/en-us/library/6hws6h2t.aspx

First - may be more pragmatic to look at WPF, or hosting some WPF elements inside winforms (which is supported - like so ).首先 - 可能更务实地查看 WPF,或者在 winforms 中托管一些 WPF 元素(支持 -像这样)。 Other than that - you can do all your own painting if you want;除此之外——如果你愿意,你可以自己画画; but it is a lot of work.但这是很多工作。

Any reason why you don't use WPF?你有什么理由不使用 WPF? You have much more more UI control if you went down the route.如果你沿着这条路线走,你会有更多的 UI 控制。

If you must go with WinForms then there are many commercial solutions like DevExpress .如果您必须使用 WinForms,那么有许多商业解决方案,例如DevExpress If you really want you own look and feel it'll be alot of work.如果你真的想要你自己的外观和感觉,那将是很多工作。

Yes.是的。 You can create your own controls.您可以创建自己的控件。 It is called a User Control.它被称为用户控件。 Just select Add->and User Control.只需选择添加-> 和用户控制。

WPF is a good alternative if you want your windows form to look fancy.如果您希望 Windows 窗体看起来很漂亮,WPF 是一个不错的选择。

I'm puzzled, you are doing WinForms development, yet in comments say you have done many months of WPF development, but WPF is not good enough because it is not cross platform.我很困惑,你是在做WinForms开发,评论里说你做了好几个月的WPF开发,但是WPF不够好,因为它不是跨平台的。

How is WinForm more cross platform, and have you seen how ugly WinForms looks under mono on a Mac as it's draw via X11. WinForm 是如何更跨平台的,你有没有看到 WinForms 在 Mac 上的单声道下看起来有多丑,因为它是通过 X11 绘制的。

If you want style and cross platform, go for Flex or Silverlight, as your already know WPF I'd go the Silverlight route.如果您想要风格和跨平台,请选择 Flex 或 Silverlight,因为您已经知道 WPF,我会选择 Silverlight 路线。

It's cross platform, and has all the beauty of WPF, but at the cost of reduced functionality out of the box.它是跨平台的,具有 WPF 的所有优点,但代价是开箱即用的功能减少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM