Solved

VB.Net: Resize Controls when form resizes

Posted on 2012-04-05
3
597 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now