C#面板布局问题
我在 C# 应用程序中创建了一个面板,其中包含 5 行文本框。
文本框动态添加到面板。它的宽度为 500 像素,每个文本框的宽度为 100 像素。
第一个文本框位于 x 位置 0,第二个文本框位于 100,第三个文本框位于 200,依此类推。
所以 5 个文本框应该水平填充面板。这些在我的计算机上正确显示,但在另一台计算机上,这些文本框看起来好像它们的宽度减小了并且它们没有延伸到面板的末端。他们在面板末尾留下空白区域。
谁能告诉我为什么文本框的显示会出现这种差异?
I have created a panel in c# application that holds rows of 5 textboxes.
Textboxes are added to panel dynamically. It is 500 pixels in width and each textbox is 100 pixels wide.
First textbox is at x-position 0, second at 100, third at 200 and so on.
So the 5 textboxes should fill the panel horizontally. These are shown correctly at my computer but at another computer these textboxes appear as if their width is reduced and they do not extend to end of the panel. They leave blank space at the end of panel.
Can anyone tell me why is this difference in display of textboxes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这可能有几个不同的原因。取决于您使用的是 WinForms(我假设)还是 WPF。 Windows中有一个可以更改的系统DPI。 Windows Vista 和 7 更多地利用了这一点。另一个问题可能与 Windows 主题有关(使用障碍主题)。 如何检查系统 DPI
There could be a few different reasons for this. Depending on if you are using WinForms (which I am assuming) or WPF. There is a system DPI that can be changed in windows. Windows Vista and 7 take advantage of this more. The other issue could be with the windows themes (play with the handicap themes). How to check your system DPI
我认为问题在于在具有不同 Windows 主题的计算机中显示文本框。
使用经典窗口控制时,它以与在计算机上打开主题时不同的方式计算空间。
I think that the problem is in displaying textboxes in computers with diferent Windows themes.
With Classic windows controls it compute space in different way than when themes are turned on on computer.
要尝试的一些事情,请确保
面板和文本框上的 AutoSize
属性设置为 false。另外,请确保PreferredSize
也已设置。
Couple things to try, make sure the
AutoSize
property is set to false on the Panel and the Textboxes. Also, make sure thePreferredSize
is also set.我遇到了类似的问题,找到了这个链接:
C# WinForms 搞乱了控制位置?
将我的主窗体的 AutoScaleMode 属性从 Font 更改为 None 或 Inherit 解决了问题(注意:更改为 Dpi 并没有解决问题)。
I was having a similar problem, and found this link:
C# WinForms messed up control positions?
where changing my main form's AutoScaleMode attribute from Font to None or Inherit solved the problem (NB: changing to Dpi did not solve it).