Solved

VB.Net: Resize Controls when form resizes

Posted on 2012-04-05
3
616 Views
Last Modified: 2012-04-06
Hi Experts,

On my main form, I have got three datagridviews, and they are just drawn during development.

But after I deploying on to many computers that I realized that different screens are not suiting my form. I.E the user wants the datagridview to control to grow when the form is resized big or small when the form is resized small.

To achieve this I had to calculate the distance between the controls size from the form border and then add the distance between in the form resize event. So that depending on the forms size the control  would fit. But it was not easy to deal with multiple controls, because I had to do the same to the rest of the gridview controls.

So is there any other alternative way to accomplish this task.

Thanks in advance.
0
Comment
Question by:baabaa_nl
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 167 total points
ID: 37813624
you can use dock property to enable auto-resizing as per the size:-



You can use Dock, or for more precise control use the Anchor property. By setting Anchor to Left, Right, Top, Bottom the control will scale with the window. By setting Anchor to Right the control will move with the right border. By setting Anchor to Top and Bottom the control will scale vertically, but have a fixed width. Just experiment
Reference : http://stackoverflow.com/questions/1636280/automatic-resizing-of-the-windows-forms-controls

http://www.codeguru.com/csharp/csharp/cs_syntax/controls/article.php/c5849/Docking-Control-in-C-That-Can-Be-Dragged-and-Resized.htm
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx
0
 
LVL 17

Assisted Solution

by:nepaluz
nepaluz earned 167 total points
ID: 37813684
It depends how you want them laid out.
1.On top of each other - Simply dock each grid to the top of the parent container and set the width to the parent container (and again in the OnResizing event of the parent form)
2. You can place these in a series of split containers which you size to your heart's content
3. More complex is using the tablelayoutpanel. You can set the widths and lengths of each row on your program load (after maximising the form) then et maximum sizes for the datagridviews.

In my experience, the tablelayoutpanel method produces the best results, but needs to be fiddled with to get to grips with it.
0
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 166 total points
ID: 37813687
You really want to use anchor and dock as much as possible to eliminate code from form_resize event.

The  SplitContainer is super useful if you need the user to be able to resize panels at run time.

Other layout controls such as TableLayoutPanelpanel and FlowLayoutPanel can add flexiblity to your layout.
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question