Benjamin Autin
Benjamin Autin

Reputation: 4171

How do I stop Visual Studio from resizing my controls?

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.

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.

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.

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

Upvotes: 11

Views: 5443

Answers (5)

Rich
Rich

Reputation: 61

I had the same problem. The instances of my user control on the form had these settings. 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.

Upvotes: 6

torial
torial

Reputation: 13121

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

Upvotes: 0

user26918
user26918

Reputation: 108

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.

Upvotes: 2

Benjamin Autin
Benjamin Autin

Reputation: 4171

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.

Upvotes: 1

Nathen Silver
Nathen Silver

Reputation: 439

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.

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

Upvotes: 0

Related Questions