当我保存表单时,为什么winform控件会自行移动 [英] Why do winform controls move on their own when I save the form

查看:351
本文介绍了当我保存表单时,为什么winform控件会自行移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在VS 2012的编辑器中关闭表单时,我遇到了按钮控件移动的问题。我只用C#工作。这是潜水我坚果,因为我必须重新定位控件,每次打开设计器。

 表格大小995,625 

按钮位置
------ --------
保存按钮617,575
删除按钮701,575
清除按钮785,575
取消按钮869,575

按钮固定在底部,右侧



表单最大大小为0,0

这些按钮上方有一个TabControl。我之前有过这个问题,我很确定它也包含一个带有TabControl的表单。



在这个表单下面有几层继承,但都是定义较小。玩这里的按钮是从这个之下的形式继承的。在这种形式下,他们被锚定在Top,Left,所以我会认为如果他们受到这种形式定位的影响,我的控件会向上移动并离开。他们一直向下和向右移动。



重现步骤。




  • 如上所述控制。 (无需进一步编辑)

  • 保存表单。 (没有明显的变化)

  • 关闭表单。

  • 重新打开表单,控件位置如下:




 按钮位置
保存按钮852,664(不可见的形式)
删除按钮936,631(不可见表格)
清除按钮1020,630(不可见表格)
取消按钮1104,664(不可见表格)

这些位置有所不同。有时他们仍然在形式上,或者只是在一个较低的位置上部分地形成并且不再对齐。他们总是低一点,就好像他们在结账过程中受到不断变化的表格大小的影响。

如果我在设计师中使表格变大,他们只是继续向下移动,并保持关闭状态。



我现在已经采用编程的方式来定位它们,但宁愿明白发生了什么,以防止它在将来发生。


<如果你有一个基本的表单(或用户控件),你在这里为控件设置了一些锚点,并且在派生的设计器中你的表单有不同的大小。

解决方案

/ p>

一种可能的解决方案是忘记锚定并使用对接。您可以通过使用 Dock 保证金填充属性;但是,第一次可能需要使用许多不可见的面板(例如,当您想使用两行以下的控件时)可能会很奇怪。这与在WPF中使用Stack / Dock面板类似。





另外,你也可以使用 TableLayoutPanel


I am having an issue with button controls moving when I close my form in the editor in VS 2012. I am working in C# exclusively. This is diving me nuts as I have to reposition the controls every time I open the designer.

Form Size 995, 625

Button             Location
------             --------
Save button        617, 575
Delete button      701, 575
Clear button       785, 575
Cancel button      869, 575

Buttons are anchored Bottom,Right

Form Maximum size is 0,0

There is a TabControl above these buttons. I have had this issue before and I am pretty sure it involved a form with a TabControl as well.

There are a couple layers of inheritance below this form, but both are defined smaller. The buttons in play here are inherited from the form just below this one. On that form they are anchored Top,Left so I would think my controls would be moving up and left if they were being effected by that forms positioning. They consistently move down and right.

Steps that reproduce.

  • Position the controls as above. (No further edits)
  • Save the form. (no visible change yet)
  • Close the form.
  • Reopen the form and the controls are located as follows:

 Button              Location
 Save button         852, 664   (off visible form)
 Delete button       936, 631   (off visible form)
 Clear button       1020, 630   (off visible form)
 Cancel button      1104, 664   (off visible form)

These locations vary. Sometimes they are still on the form, or partially on-form just in a lower position and no longer aligned. They are always lower and to the right as if they were being effected by a changing form size during the closing process.

If I make the form larger in the designer, they just keep moving down and right staying off-form.

I have resorted to positioning them programmatically for now, but would rather understand what is happening so as to prevent it in the future.

解决方案

This happens often if you have a base form (or user control) where you set some anchors for the controls and in derived designer your form has a different size.

A possible solution is to forget anchoring and to use docking instead. You can achieve everything by using the Dock, Margin and Padding properties; however, it can be strange for the first time that you might need to use many invisible panels (for example when you want to use two lines of controls below each other). This is a similar approach as using Stack/Dock panels in WPF.

Additionally, you can play with the TableLayoutPanel as well.

这篇关于当我保存表单时,为什么winform控件会自行移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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