简体   繁体   English

C#-Windows XP Professional上的布局问题

[英]C# - Layout problem on Windows XP professional

I am developing a C# application with .NET Framework 2.0. 我正在使用.NET Framework 2.0开发C#应用程序。

The problem is, that on my client's PC, the controls get expanded, layout changes (positions of the controls gets changed), sometimes buttons get missed entirely. 问题是,在我的客户的PC上,控件扩展了,布局改变了(控件的位置改变了),有时按钮完全丢失了。 It happens even on Forms with 2-3 TextBoxes, 2-3 Buttons and some Labels. 即使在带有2-3个文本框,2-3个按钮和一些标签的窗体上,也可能发生这种情况。 I tried a lot of investigations. 我尝试了很多调查。 I tried to show a message in the form's resize event. 我试图在表单的resize事件中显示一条消息。 But it doesn't get called. 但是它没有被调用。 After digging a bit more, it seemed that in Designer.cs file even though ResumeLayout (false) is being called for the form, but this causes the the expansion/disposition of the controls. 进行更多挖掘之后,即使正在为表单调用ResumeLayout(false),在Designer.cs文件中似乎也是如此,但这会导致控件的扩展/配置。

My Client is using Windows XP professional on his Dell laptop. 我的客户在他的戴尔笔记本电脑上使用Windows XP Professional。 He is able to reproduce the issue on other laptops with Windows XP professional. 他能够在其他装有Windows XP Professional的笔记本电脑上重现该问题。 But not in other OSes (like Windows XP Home or Windows Vista). 但不适用于其他操作系统(例如Windows XP Home或Windows Vista)。 In my desktop with Windows XP professional, it is not reproducible. 在装有Windows XP Professional的桌面上,它是不可复制的。

How can this issue be resolved? 如何解决这个问题?

Are you sure it has anything to do with the OS? 您确定它与操作系统有关吗? It sounds more like a dpi issue. 听起来更像是dpi的问题。 'Normal' is 96 dpi. “正常”为96 dpi。 If the form was designed at 96 dpi, it would probably look different at a different setting. 如果将表格设计为96 dpi,则在不同的设置下看起来可能会有所不同。

See this article for how to check/change the dpi settings in XP. 请参阅本文 ,了解如何在XP中检查/更改dpi设置。

Edit: I forgot to mention that you can use the TableLayoutPanel Control to layout your form. 编辑:我忘了提到您可以使用TableLayoutPanel控件来布局窗体。 Using the auto-sizing capabilities will help keep things looking 'normal' at any dpi setting. 使用自动调整大小功能将有助于使任何dpi设置的内容都保持“正常”状态。

It's probably due to the DPI setting in Windows XP. 这可能是由于Windows XP中的DPI设置所致。

If you're using the standard (96) DPI setting, but they're setup using a alternative one (ie: 120), it often will mess up layouts of controls. 如果您使用的是标准(96)DPI设置,但使用其他设置(即:120)进行设置,则通常会弄乱控件的布局。

The "right" way to handle this is to try to automatically build your layouts using layout elements that can resize as needed. 解决此问题的“正确”方法是尝试使用可以根据需要调整大小的布局元素自动构建布局。 This is difficult in Windows Forms (and one of the things WPF fixes). 在Windows窗体中(这是WPF修复的问题之一),这很难。

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

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