Anchoring and docking (problem with sizable form)

M

Mad Joe

Hi!

I have a window form that contains 4 elements (2x2) on one panel.
Those 4 elements are GroupBoxes of the exact same size, sorted like this:
groupBox1 groupBox2
groupBox3 groupBox4

While resizing a Form window manually, I would like to resize
automatically each groupBox by keeping the same ratio:
Width of each groupBox = 50% of Panel-width
Height of each groupBox = 50% of Panel-height


I'm playing with applying different values to Anchor properties, but
still can't make it right.

Example:
 
B

Bruce Wood

The only way to do this with the current version of WinForms under .NET
is to get rid of the anchoring, etc. on the GroupBoxes, react to the
Panel.Resize event and resize the group boxes in code.

The problem is that the way that panel docking and anchoring works
right now in .NET, you always have to give one panel preference on
resize. You can DockStyle.Left the left-hand panel and DockStyle.Fill
the right-hand panel, which will leave the left panel the same size as
the right on resize, or the reverse. The same goes for top and bottom.
There is no way to tell WinForms (under .NET) to "keep the proportion
the same". (Zeitgeist is a funny thing: a poster in the GotDotNet
message boards was just asking exactly the same question.)

So, your only recourse is to subscribe to the Panel.Resize event and
within your event handler move and resize the group boxes
programmatically. (Make sure to remove any anchoring or docking from
them so that you're not fighting against WinForms in the process.)

I've heard rumours that the v2.0 framework will include some
enhancements to WinForms layout management. I hope so: where layout
management is concerned I found moving from Java to C# a step down. It
would be nice to see it fixed.
 
M

Mad Joe

Bruce said:
So, your only recourse is to subscribe to the Panel.Resize event and
within your event handler move and resize the group boxes
programmatically.

I have VS .NET 2003 and this is a brand new information for me.
Thank you very much, Bruce... I'll do it programmatically then.
I've heard rumours that the v2.0 framework will include some
enhancements to WinForms layout management. I hope so: where layout
management is concerned I found moving from Java to C# a step down. It
would be nice to see it fixed.

I've already found few more bugs in layout management and bugs like this
one: accessing the Text or RichText property of a .NET RichTextBox (even
reading from it) clears the Undo/Redo buffer, so CanUndo and CanRedo
yield false after that!

I really hope that the Framework v2.0 will fix all of this stupidities!

Have a nice day! :)
 

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