开发者

Windows Forms resolution problem

开发者 https://www.devze.com 2022-12-17 13:19 出处:网络
I have developed a 1024 *780 resolution screen in Windows Forms, 开发者_StackOverflow中文版but some say that it does not fit properly at higher resolutions. Is there any way to handle this?

I have developed a 1024 *780 resolution screen in Windows Forms, 开发者_StackOverflow中文版but some say that it does not fit properly at higher resolutions. Is there any way to handle this?

Is there a way to make Windows Forms applications look the same at ALL resolutions?


My recommendation is not so much to "make it look the same" on all screens, but rather to design the GUI so it scales up and down more gracefully. Layout managers, docking, and anchors are your friends in Winforms. The TableLayoutPanel is quite useful for this sort of thing. Splitters also help...

Finally, this is one of those problems that WPF sets out to solve. WPF makes extensive use of layout managers. It feels much more like Java or GTK than Winforms or even VB (old school VB).


This is the sort of thing that makes you say "there's got to be a better way."

My solution for this one time was to declare a global ScalingFactor variable that was tied to the current screen resolution. Then, the sizes of every visual element were multiplied by that factor.

So, if I designed my form for resolution A, and resolution B is 1.2x larger, the width of window A will be with * 1.2, the fonts will be fontSize * 1.2, the textbox dimensions will be dimensions * 1.2.

Not fun.

There may be 3rd party tools that you can buy and will perform this scaling.

One other thing to check before you run down any of these roads is whether it is actually the screen resolution or the dpi settings that are causing it to look bad. Usually a higher resolution will only make it look smaller, but an atypical dpi, such as when the user selects "large fonts" will wreak havoc.


You can use anchor property of item, and autoScaleMode property of form set it equals 'None'.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号