Windows窗体和高DPI屏幕 [英] Windows Forms and High DPI Screens
问题描述
我有一个名为TMO的Outlook加载项( http://gotmo.co.uk ),其中包含单击Outlook工具栏中的帮助"按钮时打开的Windows窗体.问题是,当我在高DPI屏幕(例如Surface Pro)上使用TMO时,表单呈现出非常复杂的外观(请参见屏幕截图).但是,在其他笔记本电脑上,表格可以正确显示.
I have an Outlook Add In called TMO (http://gotmo.co.uk) which has a Windows Form that is opened on the click of the Help Button in the Outlook toolbar. The problem is that when I use TMO on High DPI Screens such as Surface Pro the form renders very convoluted (see screenshot). However on other laptops the form renders correctly.
实际上,如果我在Surface Pro上运行测试应用程序,并从该应用程序加载正确呈现的相同表单.请参阅随附的屏幕截图.
In fact if I run a test app on Surface Pro from where I load the same form it renders correctly. See the attached screenshots.
到目前为止,根据我的阅读,Windows窗体需要特殊处理才能在高DPI屏幕上正确呈现.但是我无法弄清楚要编写什么代码才能做到这一点.我的两个具体问题是
From my reading so far Windows Forms need special handling to render properly on high DPI screens. But I am unable to figure out what code needs to be written to do this. My two specific questions are
- 当从Outlook vs STand Alone中启动时,为什么相同的表单在High DPI屏幕上呈现出差异?
- 在高DPI屏幕上处理Windows帧渲染需要(一般)编写什么代码.
推荐答案
我最终通过稍微重新设计表单以使其在所有屏幕上正确呈现来解决了该问题.另外有帮助
I eventually solved it by re-designing the forms slightly so that they render correctly on all screens. In addition following helped
- 将各个控件分组到容器中,例如组框和面板.
- 在每个父容器中正确使用控件的Anchor属性,以便它们在其父容器中缩放.
- 将父窗体的AutoScaleMode设置为Dpi,将AutoSizeMode设置为GrowAndShrink
我能够跨表格重复执行上述3个步骤,并可靠地对其进行更改,使其可以在高DPI"和常规屏幕上正常工作
I was able to follow the above 3 steps repeatedly across forms and change them reliably to work on both High DPI and regular screens
这篇关于Windows窗体和高DPI屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!