如何在不同的操作系统中使winform GUI外观相同? [英] How to make winform GUI appearance the same in different operating systems?

查看:47
本文介绍了如何在不同的操作系统中使winform GUI外观相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Winform应用程序是使用visual studio 2013开发的,操作系统是Windows 8.但是当我们在Windows 7操作系统中运行应用程序时,GUI会有所不同(不是所有的Windows 7机器都有)。但是它运行完美。 Windows 10机器。



我尝试了什么:



我尝试过改变所有形式的控件的高度,填充等。但它不起作用。

解决方案

你做出的关键决定:你会忽略吗?用户选择的颜色,字体,样式,主题等;或者,你打算合作那个。



这个没有简单的答案。从具有不同分辨率(位深度)的不同屏幕尺寸的用户开始,将显示出事物的显示方式的一些变化。你可以试着让你的现代应用在某人的640x480屏幕上看起来很棒。除非你别无选择,否则我只是想忘了XP的设计和使用Aero的人:那是另一个问题区域。



WinForms GDI +渲染引擎是现在是图形引擎古董的东西; imho,对于具有特效,动画,淡入淡出,旋转等的图形丰富的应用程序,更好地前往WPF(或SilverLight ......仍然是SilverLight活着)。



您可以尝试并确保在开发时使用机器的Windows默认设置;这意味着当用户在他们的机器上运行它时,他们看到的将反映操作系统默认值,以及他们设置的颜色/字体/主题首选项。 ......这就是拥有那些外观和默认设置的重点,这就是Windows风格指南的内容。



如果你受到约束并决定控制 x在您的应用中必须以背景颜色MidnightBlue和前色GhostWhite显示:然后明确设置。让我再说一遍:当你没有默认值时:你必须设置为默认值以外的东西。



并且,Visual Studio提供的基本WinForm控件:那些将会有一些变化。对于给定的控件,请查看(通过属性浏览器)它是否提供各种内置样式选项(Win 7,Office等),并尝试利用它。



如果你想坚持使用默认设置,最好的策略是总是有一台机器来测试用户使用的典型功能。



那些希望拥有自定义外观的开发人员可以进入主题,其中可能包括自定义形状的表单,控件,特殊渐变背景等。这里有许多资源,并且在网络上使用WinForm应用程序进行主题化。只是做一个搜索。



但是,如果你真的想要主题,并对所有内容进行矢量缩放,那么UI在任何尺寸缩放时看起来都很好:考虑WPF,而不是WinForms 。 WPF还有一个我认为可能有用的VisualStateManager工具(我还没用过)。



那么,应用程序提供自己运行的极端主题 -time编辑器为每个控件和表单设置颜色,字体,大小等。很多工作!



最后,您可以探索让应用程序在启动时读取操作系统版本,并在代码中使用if / else或switch / case,评估根据不同版本进行一些视觉变化。有多种方法可以做到这一点:[ ^ ]。



以下是一些建议,可供您研究可能相关的.NET的其他方面您的查询:



1. UICulture



2.读取WinForm的DisplayRectangle和ClientRectangle属性申请启动时(或表格显示后)。这些属性,以及FormBorderStyle,Padding等读取属性,可以帮助您找出可以使用的精确矩形。



3. AutoScaleMode和AutoSizeMode属性也可以被利用。绝对检查AutoScaleMode.Font和AutoScaleMode.dpi之间的差异



而这一切只是热身。


< blockquote> Windows 8具有不同的[Metro]用户界面设计。 Windows 7和Vista具有相同的UI外观。 Windows XP和其他旧操作系统有自己的UI,它与另一个不同。因此难以在不同平台上保持相同的外观。我的建议是WPF,请查看此讨论,

Windows - Visual Studio C#桌面应用程序GUI在不同的机器上呈现不同的方式? - 堆栈溢出 [ ^ ]


My Winform application is developed using visual studio 2013, and the operating system is windows 8. But when we run the application in windows 7 operating system, the GUI varies (not for all windows 7 machines).But it runs perfectly in windows 10 machines.

What I have tried:

I tried changing the height,padding etc. of controls in all the forms .but it does not work.

解决方案

The key decision for you to make: are you going to ignore the users' choice of colors, fonts, styles, themes, etc.; or, are you going to "work with" that.

There's no "easy answer" for this one. To start with users with different screen-sizes with different resolutions (bit-depth) are going to show some variation in how things appear. You could go nuts trying to make your modern app look good on somebody's 640x480 screen. Unless you have no choice, I'd simply write-off thinking about design for XP, and someone using Aero: that's another problem area.

WinForms GDI+ rendering engine is something of a graphic-engine antique now; imho, for graphic rich apps with special effects, animations, fades, rotations, etc., better to head for WPF (or SilverLight ... is SilverLight still "alive").

You can try and make sure you use the Windows default settings for your machine as you develop; that means when the user runs it on their machine what they see will reflect the OS defaults, and the color/font/theme preferences they've set. ... That's the whole point of having those look-and-feel defaults, that's what Windows Style Guidelines are about.

If you are bound and determined that Control "x" in your app must appear with background color MidnightBlue, and forecolor GhostWhite: then set those explicitly. Let me repeat: when you don't the default: you must set to something other than the default.

And, the basic WinForm controls that are provided with Visual Studio: those are going to be rendered with some variations. For a given Control, look at (via the Property Browser) whether it offers various built-in styling options (Win 7, Office, etc.), and try and exploit that.

The best strategy if you are going to stick with the defaults is always have a machine to test on that's typical of what your users are using.

Those developers who want to have a custom look-and-feel get into "theming," which may include custom-shaped Forms, Controls, special gradient backgrounds, etc. There are numerous resources here and on the web for theming with a WinForm app. Just do a search.

But, if you really want theming, and vector-scaling of everything so the UI looks good at any size zoom: consider WPF, not WinForms. WPF also has a VisualStateManager facility I assume could be helpful (I haven't used it).

Then, there's "extreme theming" where the app offers its own run-time editor to set colors, fonts, sizes, etc., for every control and Form. Lots of work !

Finally, you could explore having your app read the OS Version when it starts up, and, in your code, use if/else, or switch/case, evaluation to make some visual change based on different versions. There a variety of ways you can do that: [^].

Here are some suggestions for you to research other aspects of .NET that may be relevant to your query:

1. UICulture

2. reading the DisplayRectangle and ClientRectangle properties of a WinForm on application start-up (or after the Form is shown). these properties, plus reading properties like FormBorderStyle, Padding, etc., can help you figure out the precise rectangle you can work with.

3. the AutoScaleMode, and AutoSizeMode properties can also be exploited. Definitely examine the differences between AutoScaleMode.Font and AutoScaleMode.dpi

And, all this is just the "warm-up."


Windows 8 has different [Metro] User Interface design. And Windows 7 and Vista has same UI appearance. Windows XP and other old Operating systems has its own UI which is different from another. So maintaining same appearance on different platforms is difficult. My suggestion is WPF, Check this discussion,
windows - Visual Studio C# desktop application GUI is rendering differently on different machine? - Stack Overflow[^]


这篇关于如何在不同的操作系统中使winform GUI外观相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆