Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB.Net: Resize Controls when form resizes

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET (2008) - Refactoring Question 2 23
vb.net help 4 34
No Data for DropDown List 2 28
ASP.NET/VB: Convert Date and Time to YYYY-MM-DDTHH:MM:SS 3 10
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

792 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