high DPI problems

て烟熏妆下的殇ゞ 提交于 2019-12-19 03:19:16

问题


I have a problem with the display of our .NET Windows application under high dpi settings.

All forms are set to AutoScaleMode = DPI, but this does not solve all the problems.

Basically labels end up expanding in size to cope woth the font being bigger, but the location of other controls does not change and we end up with lables obscuring other controls or eachother.

The screen should look like this: http://www.manageinvest.com/good.jpg ..and on high DPI it ends up looking like this: bad.jpg (this is my first post so i am only allowed one link)

Any suggestions?

Thanks in advance,

Kristian


回答1:


In theory, font and DPI scaling in Winforms are automatic. In practice... not so much.

I've noticed that it copes better with vertical scaling than horizontal, but even then it's far from perfect.

In my experience, scaling is only reliable when you do one of two things:

  1. Don't use the designer at all. This is quite painful, but it does give you the requisite amount of control over your layout.

  2. Use the built-in layout controls - specifically, the FlowLayoutPanel and TableLayoutPanel. These guys are your best friends; I rarely do anything in Winforms without them anymore.

In your case, I'd probably go with #2. Based on the screen capture, I think it would be quite easy to fit your layout into a combination of TableLayoutPanel and FlowLayoutPanel containers - possibly even just one TableLayoutPanel.




回答2:


You should look into the AutoScaleMode and AutoSize features. Combined with the docking abilities you should be able to achieve what you want.

I had a really good article on that but the link is dead... anyway, this should get you started:

http://msdn.microsoft.com/en-us/library/ms229605.aspx

http://www.sellsbrothers.com/writing/winformsAutoScaling.htm

http://msdn.microsoft.com/en-us/library/system.windows.forms.autoscalemode.aspx




回答3:


This may not solve your problem.

But we learnt the hard way that Label and the text controls should be stacked vertically, i.e. place the Text Box below the Label, instead of next to the label. This solved a lot of problems for us including support for multiple languages as text width in different languages can be more than English text



来源:https://stackoverflow.com/questions/2114857/high-dpi-problems

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!