Resizing question.

P

Poster Matt

I know this is a language group, but I can't get an answer to this question
elsewhere and I figured at least a large chunk of the readers of this group
are Visual C# users.

I've a problem resizing a form in 'design' mode of Visual C# 2008 Express.

There are loads of controls in my form, style 'sizable', which have a
horribly complex set of anchoring settings (which took me ages to set up) so
that the form resizes appropriately.

Now I want to add a menu bar to the top. I can't extend the size of the form
downwards in the designer so that I can then select all the controls and
move them all down a bit to give room at the top for the menu. Instead when
I extend the size of the form downwards, all the controls resize and move
with it.

Is there a quick way I can temporarily stop this from happening which won't
kill all my anchoring (and control positions) settings but will allow me to
resize the dialog to fit the menu in?

Thanks.
 
J

Jeff Johnson

I know this is a language group, but I can't get an answer to this question
elsewhere and I figured at least a large chunk of the readers of this group
are Visual C# users.

I've a problem resizing a form in 'design' mode of Visual C# 2008 Express.

There are loads of controls in my form, style 'sizable', which have a
horribly complex set of anchoring settings (which took me ages to set up)
so that the form resizes appropriately.

Now I want to add a menu bar to the top. I can't extend the size of the
form downwards in the designer so that I can then select all the controls
and move them all down a bit to give room at the top for the menu. Instead
when I extend the size of the form downwards, all the controls resize and
move with it.

Is there a quick way I can temporarily stop this from happening which
won't kill all my anchoring (and control positions) settings but will
allow me to resize the dialog to fit the menu in?

Have you tried adding the menu at all? The ToolStrip uses docking, which
shouldn't mess with the rest of your form. (Note the word SHOULDN'T....)

In the event simply dropping a menu on your form doesn't do what you want,
try using the Size property of the form in the Properties window. I think
(think) you can change that without the other controls resizing (as opposed
to resizing the form with your mouse).

If THAT doesn't work, close your solution and open the xxx.Designer.cs file
that corresponds to your form in a text editor. Change the this.Size = new
Size(xxx, yyy) line to the new size. Reopen the solution in VS, select all
your controls, and move them down.
 
P

Poster Matt

Jeff said:
Have you tried adding the menu at all? The ToolStrip uses docking, which
shouldn't mess with the rest of your form. (Note the word SHOULDN'T....)

Yes I'd tried that and it didn't 'mess' with the form, but the menu
overlapped a control at the top.

In the event simply dropping a menu on your form doesn't do what you want,
try using the Size property of the form in the Properties window. I think
(think) you can change that without the other controls resizing (as opposed
to resizing the form with your mouse).

Again I'd already tried that and it resized the controls as if I'd manually
dragged the form to make it bigger.

If THAT doesn't work, close your solution and open the xxx.Designer.cs file
that corresponds to your form in a text editor. Change the this.Size = new
Size(xxx, yyy) line to the new size. Reopen the solution in VS, select all
your controls, and move them down.

Bingo !!

In fact there was no "this.Size = ..." code but I used "this.ClientSize =
...." instead and changing that made the form bigger without the controls
resizing as well. Of course I had to close and reopen Visual C# several
times while I fine tuned the exact amount to make the form bigger by - but
it has worked perfectly.

Thanks so much for your help. It's really appreciated.

Cheers.
 
J

Jeff Johnson

Again I'd already tried that and it resized the controls as if I'd
manually dragged the form to make it bigger.

Sometimes the IDE can be a little TOO helpful....

Glad to hear you got it fixed. (Although I was positive method 3 would work.
It makes me laugh when I see the comment in the Designer.cs file that says
"do not modify the contents of this method with the code editor." They
really need to add "unless you have to because using the designer is
screwing you over.")
 
P

Poster Matt

Jeff said:
Sometimes the IDE can be a little TOO helpful....

Glad to hear you got it fixed. (Although I was positive method 3 would work.
It makes me laugh when I see the comment in the Designer.cs file that says
"do not modify the contents of this method with the code editor." They
really need to add "unless you have to because using the designer is
screwing you over.")

Yes I've noticed that comment too. :)

I think the Visual C# options pertaining to the Windows Form Designer should
include an option to disable anchoring when in design mode, so that it can
be ticked on and off while a user is designing their form. Maybe in the next
version but I won't be holding my breath.

If anyone knows of an IDE solution and is coming to this thread later,
please do reply - I know that I'm going to need to do this again, probably
several times, and it'd be more convenient not to have to solve the problem
by this method.

Thanks again Jeff.
 
K

kndg

Poster said:
[...]
If THAT doesn't work, close your solution and open the xxx.Designer.cs
file that corresponds to your form in a text editor. Change the
this.Size = new Size(xxx, yyy) line to the new size. Reopen the
solution in VS, select all your controls, and move them down.

Bingo !!

In fact there was no "this.Size = ..." code but I used "this.ClientSize
= ...." instead and changing that made the form bigger without the
controls resizing as well. Of course I had to close and reopen Visual C#
several times while I fine tuned the exact amount to make the form
bigger by - but it has worked perfectly.

Thanks so much for your help. It's really appreciated.

Cheers.

Hi Matt,

I have this exactly same problem before and tend to choose option #3 as
Jeff had suggested. But you don't need to close and reopen Visual
Studio. Just manually edit the xxx.Designer.cs file (In Solution
Explorer, you have to click plus-mark on xxx.cs file to show it). When
done, just switch to designer back and it will reload with new value.

Another option is to select all the controls that you want to preserve,
click cut, resize the form, and then click paste.

Regards.
 
P

Poster Matt

kndg said:
I have this exactly same problem before and tend to choose option #3 as
Jeff had suggested. But you don't need to close and reopen Visual
Studio. Just manually edit the xxx.Designer.cs file (In Solution
Explorer, you have to click plus-mark on xxx.cs file to show it). When
done, just switch to designer back and it will reload with new value.

Another option is to select all the controls that you want to preserve,
click cut, resize the form, and then click paste.

Oh yes you're right - there's no need to close and re-open. I should have
tried that yesterday and saved myself some time.

Also the cut, resize, paste, works too, though I must admit it's against
every instinct of mine to cut everything like that and put my faith in paste
(and undo) - so much so that I backed up my project before even testing that
method. :)

Thanks kndg.

By the way do Microsoft developers read this group? This anchoring sizing
problem must cause nightmares for almost anyone using anchoring. The only
way it wouldn't is if anchoring was the very last thing implemented in an
application whose design subsequently never changes or at least never
requires even the tiniest alteration in form sizing - and that probably
equates to the empty set. Microsoft developers please note than an option
needs to be added to switch on/off anchoring while in design mode or a
property needs to be added to class Form which turns anchoring on/off. Cheers.
 
J

Jeff Johnson

I have this exactly same problem before and tend to choose option #3 as
Jeff had suggested. But you don't need to close and reopen Visual Studio.
Just manually edit the xxx.Designer.cs file (In Solution Explorer, you
have to click plus-mark on xxx.cs file to show it). When done, just switch
to designer back and it will reload with new value.

Interesting. This is what I was originally going to write for #2, but then I
figured that this would be the same as changing the value in the Properties
window, i.e., the form is "live" and the IDE would recompose everything on
the fly and still mess with control sizes due to the Anchor settings.
 
P

Poster Matt

Jeff said:
Interesting. This is what I was originally going to write for #2, but then I
figured that this would be the same as changing the value in the Properties
window, i.e., the form is "live" and the IDE would recompose everything on
the fly and still mess with control sizes due to the Anchor settings.

Since you find this interesting ;) you may also like to know that after
changing the size value in xxx.Designer.cs it is not until you click on the
design window that the dialog actually resizes, this happens after a very
brief pause so you actually see the dialog resizing, rather than switching
back to an already resized dialog as I was expecting to happen.
 
J

Jeff Johnson

Since you find this interesting ;) you may also like to know that after
changing the size value in xxx.Designer.cs it is not until you click on
the design window that the dialog actually resizes, this happens after a
very brief pause so you actually see the dialog resizing, rather than
switching back to an already resized dialog as I was expecting to happen.

Nah, I knew that. Actually, what I see happening is the window vanishes and
gets completely rebuilt, which, for a complex window, can be kind of
time-consuming (on the order of SECONDS!!!) and annoying.
 
P

Poster Matt

Jeff said:
Nah, I knew that. Actually, what I see happening is the window vanishes and
gets completely rebuilt, which, for a complex window, can be kind of
time-consuming (on the order of SECONDS!!!) and annoying.

Oh yes, that's exactly what it does Jeff, forgot about the vanishing, but on
my PC it's more of a flash, and nowhere near 'seconds' to rebuild -
definitely less than a second - my PC is pretty damn speedy though. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top