views:

812

answers:

6

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.

A: 

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.

Nathen Silver
I tried adding a panel for both the controls, but it didn't work too well either.
toast
+1  A: 

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.

toast
+1  A: 

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.

It would be nice if the designer worked all the time, but sometimes its better to use this solution to get the job sorted and move on rather than worrying about why the designer has some flaws.
Scott Langham
This seems like the best answer to my problem.
toast
A: 

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

torial
A: 

post the code from the designer; are you sure that you haven't also set the Dock property to Fill?

Steven A. Lowe
Dock is None. This isn't a problem of the control acting wrong. When run, the application runs as its supposed to. Just in the designer, the height and/or width become way too large to work with.
toast
@[toast]: ok. i've only run into this kind of problem once before, and was unable to solve it - except by setting things in the constructor as suggested above.
Steven A. Lowe
A: 

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.

Rich