如何阻止Visual Studio调整控件的大小?

时间:2021-05-03 07:12:41

Visual Studio 2008 SP1 (although IIRC, the behavior was present in 2005 as well) keeps resizing a couple of grid controls (Janus.GridEx to be precise) I use.

Visual Studio 2008 SP1(虽然IIRC,行为也出现在2005年)继续调整我使用的几个网格控件(准确地称为Janus.GridEx)。

I can resize them back to normal, save, and compile just fine. When it does compile, these two controls will expand to ridiculous values.

我可以将它们恢复正常,保存并编译得很好。当它编译时,这两个控件将扩展为荒谬的值。

More Information: This problem is related to setting the Anchor property on the control. If I set the Anchor property to opposing ends (say Left and Right), when the Designer file gets compiled, it sets the width/height of the control to the width/height of the container.

更多信息:此问题与在控件上设置Anchor属性有关。如果我将Anchor属性设置为相反的两端(比如Left和Right),则在编译Designer文件时,它会将控件的宽度/高度设置为容器的宽度/高度。

It seems that in the Designer file, the Anchor property is set before the Size property. Manually editing (I know, shame on me) the file to put the Size property first doesn't help as when the Designer file gets compiled, it seems to be rewritten from scratch as well.

似乎在Designer文件中,Anchor属性在Size属性之前设置。手动编辑(我知道,对我来说很遗憾)首先放置Size属性的文件没有帮助,因为当编译Designer文件时,它似乎也从头开始重写。

So I guess my real question is how to make VS form designer respect my initial size declaration as well as the Anchor property.

所以我想我真正的问题是如何让VS表单设计师尊重我的初始大小声明以及Anchor属性。

5 个解决方案

#1


2  

I usually solve that kind of trouble by putting the 'good' code in the form constructor, right after the call to InitializeComponent(), so it overrides any mess the automatic designer magic might cause.

我通常通过在调用InitializeComponent()之后将'好'代码放在表单构造函数中来解决这种麻烦,因此它会覆盖自动设计器魔术可能导致的任何混乱。

#2


6  

I had the same problem. The instances of my user control on the form had these settings. anchor - none autosize - false dock - none

我有同样的问题。表单上的用户控件实例具有这些设置。 anchor - none autosize - false dock - none

It still horribly resized them every time I did a build etc.

每次我做建筑等时,它仍然可怕地调整它们的大小。

I found that on the user control in the design properties it had autoscalemode set to font. I change it to none and that fixed the problem.

我发现在设计属性中的用户控件上,它将autoscalemode设置为font。我将其更改为无,并解决了问题。

#3


1  

What I'm doing currently is handling the Resize event and setting the Size on the two required controls. I feel this is a bit of a kludge given the intended effect of the Anchor property.

我目前正在做的是处理Resize事件并在两个必需控件上设置Size。考虑到Anchor属性的预期效果,我觉得这有点像kludge。

#4


0  

Usually when I have this problem, I end up using Panels and Labels (blank text) with the Dock and Padding properties on the controls to get the same visual look. Whether this would be practical for your form would depend on how it is laid out.

通常当我遇到这个问题时,我最终使用控件上的Dock和Padding属性的面板和标签(空白文本)来获得相同的视觉效果。这对您的表单是否实用将取决于它的布局。

Not the best solution because of all the extra controls, but it gets the job done.

由于所有额外的控制,不是最好的解决方案,但它完成了工作。

#5


0  

Perhaps I'm misunderstanding the question, but I think what you are looking for is the Locked property: http://msdn.microsoft.com/en-us/library/80xxxf69.aspx

也许我误解了这个问题,但我认为你所寻找的是Locked属性:http://msdn.microsoft.com/en-us/library/80xxxf69.aspx

#1


2  

I usually solve that kind of trouble by putting the 'good' code in the form constructor, right after the call to InitializeComponent(), so it overrides any mess the automatic designer magic might cause.

我通常通过在调用InitializeComponent()之后将'好'代码放在表单构造函数中来解决这种麻烦,因此它会覆盖自动设计器魔术可能导致的任何混乱。

#2


6  

I had the same problem. The instances of my user control on the form had these settings. anchor - none autosize - false dock - none

我有同样的问题。表单上的用户控件实例具有这些设置。 anchor - none autosize - false dock - none

It still horribly resized them every time I did a build etc.

每次我做建筑等时,它仍然可怕地调整它们的大小。

I found that on the user control in the design properties it had autoscalemode set to font. I change it to none and that fixed the problem.

我发现在设计属性中的用户控件上,它将autoscalemode设置为font。我将其更改为无,并解决了问题。

#3


1  

What I'm doing currently is handling the Resize event and setting the Size on the two required controls. I feel this is a bit of a kludge given the intended effect of the Anchor property.

我目前正在做的是处理Resize事件并在两个必需控件上设置Size。考虑到Anchor属性的预期效果,我觉得这有点像kludge。

#4


0  

Usually when I have this problem, I end up using Panels and Labels (blank text) with the Dock and Padding properties on the controls to get the same visual look. Whether this would be practical for your form would depend on how it is laid out.

通常当我遇到这个问题时,我最终使用控件上的Dock和Padding属性的面板和标签(空白文本)来获得相同的视觉效果。这对您的表单是否实用将取决于它的布局。

Not the best solution because of all the extra controls, but it gets the job done.

由于所有额外的控制,不是最好的解决方案,但它完成了工作。

#5


0  

Perhaps I'm misunderstanding the question, but I think what you are looking for is the Locked property: http://msdn.microsoft.com/en-us/library/80xxxf69.aspx

也许我误解了这个问题,但我认为你所寻找的是Locked属性:http://msdn.microsoft.com/en-us/library/80xxxf69.aspx