Click here to Skip to main content
13,095,218 members (67,871 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am Back with Query again, :P

I set All Field of Form1 in Vb.Net 2008 with Designer Mode.

Now I want to Set All Field Size & Location as user increases or decrease the form size.

Like If User Increases Form1 Size All Fields have to Increase Size & Location Dynamic Relate to Form's Size.

If user Decrease the Form1 Size All Fields have to Decrease Size & Location Dynamic Relate to Form's Size.

(E.G. Android SDK Installer, ACD See Viewer)

How to Code for It?

Posted 15-Jun-11 21:00pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can code it manually, in the Resize event, or you can do it one of two other ways:
For a simple form, look at the Anchor[^] property.

For more complex forms, look at setting up panels and using the Dock[^] property instead. SAKryukov has an explanation of this a solution to this question: how to dock button so that it can adjust with the form[^]
SAKryukov 16-Jun-11 3:18am
Voting less than 5 would be unfair on my side :-)
Thank you for reminding me of my past answer which I failed to add to my re-use reference list. I credited it in my answer.

Look at the difference in approaches, in first sentense:
Yours: "You can code it manually...".
Mine: "Simply stop doing it all manually." -- at first I thought I double-posted. :-)

I'm still against Anchor, but it's better then manual :-)
OriginalGriff 16-Jun-11 3:25am
:laugh: - I'm still pro Anchor for very simple forms, but doing it manually (while a total PITA) can be the only way to make it look good without going to WPF, if only because you can resize fonts and so forth if you need to. Not an option I would want to take often though.
s1a2b3 17-Jun-11 9:49am
Small Query, This Code is for Panels. How to add All Fields which I created in designer mode.
OriginalGriff 17-Jun-11 9:51am
It uses panels to hold the controls - if you look at the code you will see what he is doing.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Simply stop doing it all manually. Never use explicit sizes and location. Use many pad panels and Dock properties with Padding. It will automatically layout everything. In some cases, you can adjust container panel sizes to contents in code. Avoid Anchors property; anchored Form still needs manual alignment (can be inaccurate) and tends to flicker in resize.

See also my past answers on the topic:
Zom Out malfunctions when Screen resolution changes[^] — this is about tolerance to screen resolution but techniques are the same,
see also:
GUI Apperance - C#.Net[^],
Code behind class implementation[^].

A code sample Griff liked: how to dock button so that it can adjust with the form[^] :-).


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 16 Jun 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100