为什么form.clientsize会在Windows 10中移动我的按钮? [英] Why does form.clientsize move my buttons in windows 10?

查看:104
本文介绍了为什么form.clientsize会在Windows 10中移动我的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当简单的实用程序应用程序,最初是在VS 2010中编写的。当我将开发计算机更新到Windows 10时,应用程序无需修改即可运行,但是一个对话框上的两个按钮向上移动了23个像素,它们被部分隐藏了一个标签。令人讨厌,但是可以忍受一段时间。

我今天决定是时候纠正那个错位了,所以我把项目移到了Windows 10中的VS 2015(指定的.NET版本仍然相同)。当我打开该对话框的表单设计器时,确定按钮高23像素。所以,我把它们移回到它们所属的右下方锚定位置并保存了表格。然后,我比较了表单文件的当前版本和先前版本以及更改的唯一行在designer.cs文件中:

  this 。 ClientSize =  new  System.Drawing.Size( 284  93 ); 

在Windows 7下的VS 2010中,93为94.如果我将93更改回94,则按钮会跳回到不正确的位置,VS会将94更改回93关于ClientSize的MSDN文档听起来应该被视为只读而没有提到它可能会有什么影响。

使用designer.cs文件(只是为了笑容),我发现如果我更正了该文件中的位置,VS会将它们更改回错误的位置。将按钮放在它们所属的唯一方法是在图形设计器中移动它们,然后将它们放在我无法编辑它们的相同位置。去图。

我的Windows 10版本显而易见,但是我的分析大脑不喜欢不知道为什么会这样。很明显它是Windows 7和10之间的区别,但是......

为什么只有这一个对话框?

为什么只有那两个按钮?

无论如何,ClientSize与它有什么关系?



我尝试了什么:



在Form.ClientSize下搜索MSDN。

解决方案

好吧。从右下角到右上角更改这些按钮的锚定(我可以这样做,因为表格不允许垂直增长)会导致按钮在两个Windows版本中保持正确的位置。

其他相关数据:

*另一种形式的一个按钮是右上角的锚定。

*所有其他右下角的锚定按钮都在UserControls中,所有这些按钮都是左上角的锚定。



感谢您的建议,Ralf !!


Windows控件的行为取决于很多因素,例如:

- 容器(TableLayoutPanel,FlowLayoutPanel,Panel,GroupBox等),

- 锚点

- 保证金



参见:

解决方法:使用a排列Windows窗体上的控件TableLayoutPanel | Microsoft Docs [ ^ ]

演练:使用FlowLayoutPanel在Windows窗体上排列控件Microsoft Docs [ ^ ]

演练:为数据输入创建可调整大小的Windows窗体| Microsoft Docs [ ^ ]

Control.Anchor Property(System .Windows.Forms) [ ^ ]

Control.Margin属性(System.Windows.Forms) [ ^ ]

Control.Padding属性(System.Windows.Forms) [ ^ ]

I have a rather simple utility app originally written in VS 2010. When I updated my development machine to Windows 10, the app ran without modification, but the two buttons on one dialog moved up 23 pixels to where they get partially hidden by a label. Annoying, but tolerable for a while.
I decided today it was time to remedy that misplacement, so I moved the project to VS 2015 in Windows 10 (with still the same .NET version specified). When I open the form designer for that dialog, sure enough, the buttons are 23 pixels high. So, I moved them back to the bottom-right-anchored position they belong in and saved the form. I then compared the current and prior versions of the form's files and the ONLY line that changed is in the designer.cs file:

this.ClientSize = new System.Drawing.Size(284,93);

In VS 2010 under Windows 7, the 93 was 94. If I change the 93 back to 94, the buttons jump back to their incorrect locations and VS changes the 94 back to 93. The MSDN documentation on ClientSize sounds like it should be treated as readonly and makes no mention of what effect changing it might have.
Toying around with the designer.cs file (just for grins), I found that if I correct the locations in that file, VS changes them back to the incorrect locations. The only way to put the buttons where they belong is to move them in the graphic Designer, and it then puts them in the same locations I couldn't edit them to. Go figure.
It's obvious what to do for my Windows 10 version, but my analytical brain doesn't like not knowing why this happens. It's pretty clear that it is a difference between Windows 7 and 10, but...
Why only this one dialog?
Why only those two buttons?
What does ClientSize have to do with it anyway?

What I have tried:

Searched MSDN under Form.ClientSize.

解决方案

Well, well. Changing the anchoring of those buttons from bottom-right to top-right (which I could do because the form is not allowed to grow vertically) causes the buttons to stay in their rightful place in both Windows versions.
Other related data:
* The one button on the other form is top-right anchored.
* All the other bottom-right anchored buttons are in UserControls, all of which are top-left anchored.

Thanks for the suggestion, Ralf!!


Windows controls behaviour depends on many factors, such as:
- container (TableLayoutPanel, FlowLayoutPanel, Panel, GroupBox, etc.),
- Anchor
- Margin

See:
Walkthrough: Arranging Controls on Windows Forms Using a TableLayoutPanel | Microsoft Docs[^]
Walkthrough: Arranging Controls on Windows Forms Using a FlowLayoutPanel | Microsoft Docs[^]
Walkthrough: Creating a Resizable Windows Form for Data Entry | Microsoft Docs[^]
Control.Anchor Property (System.Windows.Forms)[^]
Control.Margin Property (System.Windows.Forms)[^]
Control.Padding Property (System.Windows.Forms)[^]


这篇关于为什么form.clientsize会在Windows 10中移动我的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆