简体   繁体   English

c# - 改变我的窗体的外观

[英]c# - changing the appearance of my windows form

I am developing a windows form.我正在开发一个窗体。 I want to change the physical appearance of the form and its controls.我想更改窗体及其控件的物理外观。 I was able to use the Skincrafter demo, however this is making the application substantially heavier.我能够使用 Skincrafter 演示,但这使应用程序变得更重。 I am not satisfied with how "heavy" it feels when navigating through tabs, moving the window, etc. It's fairly simple program and I do not have this issue when not using skincrafter.我对浏览选项卡、移动窗口等时的“沉重”感觉不满意。这是一个相当简单的程序,我在不使用 skincrafter 时没有这个问题。 When not using it, the GUI is very responsive and I want to keep it that way.不使用它时,GUI 非常敏感,我想保持这种状态。

I've tried many different skins and the results are very similar in every case.我尝试了许多不同的皮肤,结果在每种情况下都非常相似。

So I will not be using skincrafter unless someone points me out to possible reasons for this slower GUI.所以我不会使用 skincrafter,除非有人指出这种较慢的 GUI 的可能原因。 I followed their tutorial and didn't do anything else.我跟着他们的教程,没有做任何其他事情。 Simple process.简单的过程。 Before: fast GUI - after: slow GUI.之前:快速 GUI - 之后:慢速 GUI。

Can anyone recommend me another way to change the appearance of my controls/form?谁能推荐我另一种更改控件/表单外观的方法? Is there way to programatically change the appearance of controls and form, without relying on a third party skinning software?有没有办法在不依赖第三方皮肤软件的情况下以编程方式更改控件和表单的外观?

Note that I do not want my users to change skins.请注意,我不希望我的用户更改皮肤。 I want to apply one and that's it.我想申请一个,就是这样。

thank you Steve谢谢史蒂夫

Edit: The project is far from done so I am going to give WPF some real good thoughts so I don't end up doing this when I have a 4x times as large as it is right now.编辑:该项目还远未完成,所以我将给 WPF 一些真正好的想法,所以当我有现在的 4 倍大时,我最终不会这样做。 I've already start converting and it shouldn't be much of problem.我已经开始转换了,应该问题不大。 Found timer and serialport cannot be front from the toolbox and timer are replaced by dispatchtimer.发现计时器和串行端口不能在工具箱的前面,计时器被调度计时器替换。 No big deal so far.目前没什么大不了的。 One another thing that makes me want to work with WPF is that I may have the need to make graphs (plotting) to show temperature over time.让我想使用 WPF 的另一件事是我可能需要制作图表(绘图)来显示温度随时间的变化。 I use serialport to communicate with an external USB controller (virtual COM port) that reads a bunch of temperature sensors and fan speeds.我使用串行端口与读取一堆温度传感器和风扇速度的外部 USB 控制器(虚拟 COM 端口)进行通信。 I suspect graphing to be better with WPF.我怀疑使用 WPF 绘图会更好。 One last thing: it's just about colors/fonts but more about looks of the buttons, looks of the actual window (border shapes).最后一件事:它只是关于颜色/字体,但更多关于按钮的外观,实际窗口的外观(边框形状)。 What I wanted to do was something similar that is done with html and css.我想做的是用 html 和 css 做的类似的事情。 I do want to have custom labels to give them the look of a "digital display" for real time temperatures and fan speed measurements.我确实想要自定义标签,让它们看起来像“数字显示器”,用于实时温度和风扇速度测量。

again thanks all for the help provided!再次感谢大家提供的帮助!

In the distant past, I added lightweight skinning to WinForms projects by subclassing the out-of-the-box controls (Label, TextBox, etc), and having that subclass read in appearance configuration (eg color, font) from an XML file (one could also use app.config).在遥远的过去,我通过子类化开箱即用的控件(标签、文本框等),并让该子类从 XML 文件(例如颜色、字体)中读取外观配置(也可以使用 app.config)。

That approach was easy to implement, and I saw no visible performance degradation.这种方法很容易实现,我没有看到明显的性能下降。

If you just want a consistent, new look and don't need to enable the end user to pick from a variety of skins, the subclassing approach is very straightforward.如果您只想要一致的新外观并且不需要让最终用户能够从各种皮肤中进行选择,那么子类化方法非常简单。 For example, to modify the look of a Label :例如,要修改Label的外观:

public MyLabel : Label
{
    MyLabel()
    {
        this.ForeColor = Colors.Blue;
    }
}

Then, everywhere you currently have a Label in your code, use a MyLabel instead.然后,在您的代码中当前有 Label 的任何地方,请改用 MyLabel。

If you are starting a new project, I would highly recommend using WPF instead.如果您要开始一个新项目,我强烈建议您改用 WPF。 It provides a much more flexible UI framework.它提供了一个更加灵活的 UI 框架。 One key feature is that it separates the look from the UI implementation.一个关键特性是它将外观与 UI 实现分开。

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

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