Solved

VB.NET Resize datagrids as form grows and shrinks

Posted on 2015-01-30
5
154 Views
Last Modified: 2015-02-01
Hey guys, I'm pretty new to VB and have put together a form which has 3 datagrids, a few buttons and some labels.

Grid 1 contains 1 column and is located to the left of the screen, grid2 contains 5 columns and is in the middle, grid3 has 4 columns and located to the right.

I've anchored the grids as below:
Grid1: Top, bottom, left, right
Grid2: Top, bottom, right
Grid3: Top, bottom, right

When I shrink and grow the form from the top and bottom everything shrinks and grows accordingly, no problem.

When I shrink the form from the right or left, only grid1 shrinks and grows. If I drag the form in and start to shrink it, I can see grid1 is getting smaller while grid2 and grid3 remain the same size (see screenshot 1).

Not sure if this is expected or if I'm doing something wrong.

I guess what I'm trying to achieve is to have all the grids shrink, not just grid1.

I have tried anchoring grid2 to top, bottom, left and right, which then does shrink, but when the form is resized it leaves a large gap between grid1 and grid2 (see screenshot 2).


grid1-resizing-only.png
grid2-set-to-all-4-points.png
0
Comment
Question by:amaru96
  • 3
  • 2
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40581136
You're probably looking for a TableLayoutPanel:
https://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel%28v=vs.110%29.aspx

How do you want them to resize, though?

Do you want them to all keep their relative size to each other?...but take up the whole width?

It's possible to make some of them fixed width and others take up a certain percentage, etc...

You have to be very specific in describing how they should resize if you want a good answer.
0
 
LVL 1

Author Comment

by:amaru96
ID: 40581171
Hi Mike, I'd like them to all resize evenly and maintain the same distance from one another.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 40582131
You'd setup your TableLayoutPanel with 3 columns and 1 row:
TableLayoutPanel w/ 3 Columns
The percent sizes are relative to each other.  This means the third column would be 4 times as wide as the first column, and the second column would be 8 times as wide as the first column and 2 times as wide as the third.  The one row would just be any number with the percent type.

Now just add your grids to each column and set their Dock property to Fill.
0
 
LVL 1

Author Comment

by:amaru96
ID: 40582221
Thanks Mike, never used the tablelayoutPanel before but seems to do the trick.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40582652
The TableLayoutPanel is extremely flexible once you learn how to use it.  You can make controls span columns and rows, and you can even nest TableLayoutPanels (or other containers) within each other to make very complex layouts.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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