I'm stumped by some bizarre behavior in Visual Studio's forms editor. I have seen this on a couple of different forms in my application. Each time I open the form in Visual Studio's layout editor some controls will be in a different location than when I left them. Typically some buttons move up just a little bit from the lower right corner. But its not just buttons, in one case its a container panel that moves. I have to reposition them then save and close the form. I've confirmed that it is the layout editor actually changing the Location
property when the form is opened because if I save and close the form with the buttons in the correct position they will be correct at runtime.
我被Visual Studio的表单编辑器中的一些奇怪行为难住了。在我的应用程序中,我已经看到了一些不同的表单。每次我在Visual Studio的布局编辑器中打开窗体时,一些控件的位置将与我离开时不同。一般来说,一些按钮从右下角向上移动一点点。但它不只是按钮,在一种情况下,它是一个可以移动的容器面板。我必须重新定位,然后保存并关闭表单。我已经确认,当打开表单时,实际上是布局编辑器更改了Location属性,因为如果我使用正确位置的按钮保存和关闭表单,它们在运行时将是正确的。
This is not a problem with the Anchor
or Dock
properties not being set correctly. The editor is actually changing the Location
property of my control(s). I've looked at the .designer.cs file and I do not see anything unusual. I've tried deleting and recreating these controls but the problem persists.
这不是锚或停靠属性没有被正确设置的问题。编辑器实际上正在更改控件的位置属性。我查看了.designer.cs文件,没有看到任何异常。我尝试过删除和重新创建这些控件,但问题仍然存在。
Any ideas what I can do?
知道我能做什么吗?
Its not a show stopper I just have to be very careful to fix the controls manually every time I open it in the winforms layout editor.
它不是一个显示塞子,我只是需要非常小心,每次我在winforms布局编辑器中打开它时都要手动修复。
Edit: Visual Studio will actually checkout the file automatically to set the Location
to what it stubbornly thinks it should be.
编辑:Visual Studio实际上会自动检出文件,将其位置设置为它顽固地认为它应该是的位置。
5 个解决方案
#1
2
I found the answer to this problem, but it just look like a bug for me. It has never been solved since 2003 !
我找到了这个问题的答案,但对我来说它就像一个bug。自从2003年以来,它从未被解决过!
In short : Visual Inheritance does not work well with Anchoring.
简而言之:视觉继承并不适合锚定。
Complete answer here : http://weblogs.asp.net/rweigelt/archive/2003/09/24/28984.aspx
完整答案如下:http://weblogs.asp.net/rweigelt/archive/2003/09/24/28984.aspx
#2
2
The WinForms editor is a WYSIWYG which requires the editor to actually execute the layout code in order to show you exactly what the form will look like. While being extremely convenient, there are a number of chicken and egg problems that begin to wreak havoc on your editor.
WinForms编辑器是一个WYSIWYG,它要求编辑器实际执行布局代码,以便向您显示表单的具体外观。在非常方便的时候,有一些鸡和蛋的问题开始对你的编辑造成严重的破坏。
A common issue is that of sizing. Sometimes control properties are ordered incorrectly (and, being auto-generated, you cannot fix this). The result is that some needed value is not set until after the property which needs it. A famous example is the SplitContainer and the MinSize of Panel2 (see http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/ee6abc76-f35a-41a4-a1ff-5be942ae3425). It's possible that you are experiencing a similar root issue, but the result is that the location of your controls are changing.
一个常见的问题是规模大小。有时候控件属性的排序是不正确的(并且,由于是自动生成的,您无法修复它)。其结果是,某些需要的值直到需要它的属性之后才会被设置。一个著名的例子是SplitContainer和Panel2的最小大小(参见http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/ee6abc76-f35a-41a4-a1ff-5be942ae3425)。您可能正在经历一个类似的根问题,但是结果是您的控件的位置发生了变化。
I would examine the order of your properties in the Designer and try to determine if that might be the root of the issue. If it is, you may need to set some property at runtime. In general though, there is a rarely a true "fix" - the resolution is more often than not a "workaround".
我将检查设计器中属性的顺序,并尝试确定这是否可能是问题的根源。如果是,您可能需要在运行时设置一些属性。一般来说,很少有真正的“解决方案”——解决方案往往是“变通”。
These kinds of issues were part of the motivation for creating WPF. The declarative nature of XAML helps to prevent these sorts of occurrences while still providing the WYSIWYG feel.
这些问题是创建WPF的动机之一。XAML的声明性有助于在提供所见即所得的感觉的同时防止此类事件的发生。
#3
1
I agree with PaulG, its most likely an issue related to DPI
我同意PaulG的观点,这很可能与DPI有关
Please change your Video Card settings from Large (120dpi) to Normal (96 dpi).
请将显卡设置从大(120dpi)更改为正常(96dpi)。
#4
0
Its most likely an issue related to DPI. Check the designer.cs for an AutoScaleMode property and try changing it (or adding one) to set the form.AutoscaleMode = Font
这很可能与DPI有关。检查设计师。为AutoScaleMode属性设置cs,并尝试更改它(或添加一个)以设置表单。AutoscaleMode =字体
#5
0
Try locking the controls in design mode and then see how it goes.
尝试在设计模式中锁定控件,然后查看它是如何运行的。
#1
2
I found the answer to this problem, but it just look like a bug for me. It has never been solved since 2003 !
我找到了这个问题的答案,但对我来说它就像一个bug。自从2003年以来,它从未被解决过!
In short : Visual Inheritance does not work well with Anchoring.
简而言之:视觉继承并不适合锚定。
Complete answer here : http://weblogs.asp.net/rweigelt/archive/2003/09/24/28984.aspx
完整答案如下:http://weblogs.asp.net/rweigelt/archive/2003/09/24/28984.aspx
#2
2
The WinForms editor is a WYSIWYG which requires the editor to actually execute the layout code in order to show you exactly what the form will look like. While being extremely convenient, there are a number of chicken and egg problems that begin to wreak havoc on your editor.
WinForms编辑器是一个WYSIWYG,它要求编辑器实际执行布局代码,以便向您显示表单的具体外观。在非常方便的时候,有一些鸡和蛋的问题开始对你的编辑造成严重的破坏。
A common issue is that of sizing. Sometimes control properties are ordered incorrectly (and, being auto-generated, you cannot fix this). The result is that some needed value is not set until after the property which needs it. A famous example is the SplitContainer and the MinSize of Panel2 (see http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/ee6abc76-f35a-41a4-a1ff-5be942ae3425). It's possible that you are experiencing a similar root issue, but the result is that the location of your controls are changing.
一个常见的问题是规模大小。有时候控件属性的排序是不正确的(并且,由于是自动生成的,您无法修复它)。其结果是,某些需要的值直到需要它的属性之后才会被设置。一个著名的例子是SplitContainer和Panel2的最小大小(参见http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/ee6abc76-f35a-41a4-a1ff-5be942ae3425)。您可能正在经历一个类似的根问题,但是结果是您的控件的位置发生了变化。
I would examine the order of your properties in the Designer and try to determine if that might be the root of the issue. If it is, you may need to set some property at runtime. In general though, there is a rarely a true "fix" - the resolution is more often than not a "workaround".
我将检查设计器中属性的顺序,并尝试确定这是否可能是问题的根源。如果是,您可能需要在运行时设置一些属性。一般来说,很少有真正的“解决方案”——解决方案往往是“变通”。
These kinds of issues were part of the motivation for creating WPF. The declarative nature of XAML helps to prevent these sorts of occurrences while still providing the WYSIWYG feel.
这些问题是创建WPF的动机之一。XAML的声明性有助于在提供所见即所得的感觉的同时防止此类事件的发生。
#3
1
I agree with PaulG, its most likely an issue related to DPI
我同意PaulG的观点,这很可能与DPI有关
Please change your Video Card settings from Large (120dpi) to Normal (96 dpi).
请将显卡设置从大(120dpi)更改为正常(96dpi)。
#4
0
Its most likely an issue related to DPI. Check the designer.cs for an AutoScaleMode property and try changing it (or adding one) to set the form.AutoscaleMode = Font
这很可能与DPI有关。检查设计师。为AutoScaleMode属性设置cs,并尝试更改它(或添加一个)以设置表单。AutoscaleMode =字体
#5
0
Try locking the controls in design mode and then see how it goes.
尝试在设计模式中锁定控件,然后查看它是如何运行的。