Keep the ration while resizing a form

L

LBS

Hello
Does anybody found a good way to keep the ration of all controls on a form
while resizing it ?
I tried many things with the anchor and dock option but it still come up
pretty ugly as controls end up on top of each others.

A good example of what I would like to see is actually your windows
environment.
By that, I mean the display option in your regional setting.
For instance, if you are working on 800*600, and you switch to 1600*1200,
everything is resize but the ratio is kept.

Thank you
 
E

Ed Kaim

There's nothing directly in the .NET Framework to help with that, so you may
need to write some code to do intelligent resizing. Anchoring and docking
are useful, but once you start having three or more controls in any
direction it can become a mess.

..NET Framework 2.0 includes some useful stuff regarding different layout
models, autosizing, and padding, but that won't help for now.
 
G

Guest

Ed Kaim said:
There's nothing directly in the .NET Framework to help with that, so you may
need to write some code to do intelligent resizing. Anchoring and docking
are useful, but once you start having three or more controls in any
direction it can become a mess.

..NET Framework 2.0 includes some useful stuff regarding different layout
models, autosizing, and padding, but that won't help for now.
Why doesn't the dotnet class library have a system for calculating the
positions and sizes of the GUI elements at runtime, like the layout managers
in java?
Specifying the position and size of the elements in pixels isn't a good
choice for these reasons:
-the program may be used in more than one language. When the length of the
text on labels, buttons etc. changes, it would be fine if the relative
controls could automatically resize.
-a program may allow the user to change the font used for the GUI. Larger
fonts require the GUI elements to resize, otherwise not the entire text will
be visible
-the user resizes the form and the entire space should be distributed
automatically among then controls
-in a DB application it may be useful that based on the user rights some GUI
elements are visible and others not. The space should always be used
efficiently.
-in higly configurable applications the user may be allowed to define which
fields appear on the forms, which containers are on the form, which fields or
other containers they have etc.
A layout manager which calculates the size of the GUI elements would be very
useful for these reasons.
 
G

Guest

Why doesn't the dotnet class library have a system for calculating the
positions and sizes of the GUI elements at runtime, like the layout managers
in java?
Specifying the position and size of the elements in pixels isn't a good
choice for these reasons:
-the program may be used in more than one language. When the length of the
text on labels, buttons etc. changes, it would be fine if the relative
controls could automatically resize.
-a program may allow the user to change the font used for the GUI. Larger
fonts require the GUI elements to resize, otherwise not the entire text will
be visible
-the user resizes the form and the entire space should be distributed
automatically among then controls
-in a DB application it may be useful that based on the user rights some GUI
elements are visible and others not. The space should always be used
efficiently.
-in higly configurable applications the user may be allowed to define which
fields appear on the forms, which containers are on the form, which fields or
other containers they have etc.
I hope MSFT recognizes the need for a layout manager in these cases.
 
B

Bob Powell [MVP]

Layout is provided for. There are a few examples of writing a layout
manager. See GotDotNet for details.

http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsFormLayout.aspx

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

Thank you for the reply
Yes I have seen the examples in the SDK. If I'm not wrong, the built-in
layout system keeps the GIVEN SIZE (in pixels) for the elements with
DockStyle Left, Right, Top and Bottom, and assigns the remaining space for
the element with DockStyle Fill.
The examples found at http://dotnet.jku.at/projects/slm/ go further the
winforms built-in borderlayout system and provide several choices. When the
container is resized, RubberLayout stretches every control (relative to the
initial size) with the same factor, GridLayout divides the available width
and heigth equally among the elements so they have all the same size,
FlowLayout doesn't change the size of the contained controls but only their
positions...
But in all this stuff something is missing: the ability of the single GUI
elements to calculate the space they need, and so the size and positions of
the entire form.
For example, a Button or Label should calculate its size based on its Text
and Font. A container such as a Panel or Form or TabPage should calculate its
size based on the conatained controls and subcontainers and the desired
layout mode...
I (and perhaps others) would like to build a form WITHOUT having to specify
the size of anything in pixels, because giving the size in pixels isn't a
good choice when the font, caption etc can change at runtime.
see also
http://www.windowsforms.net/Forums/ShowPost.aspx?tabIndex=1&tabId=41&PostID=1729
 
A

alejandro lapeyre

You want the same features as in a web page?

The windows forms are not designed to support that kind of automatic
resizing.
Keep enough space for your varying captions, use the default font, keep the
focus on your application purpose and wait for the next release.

regards
Alejandro Lapeyre
 

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