?
Solved

VB.Net: Resize Controls when form resizes

Posted on 2012-04-05
3
Medium Priority
?
651 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
[X]
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
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 668 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 668 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 664 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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