WinForms: Making a set of controls scale vertically
I have a Windows Form that displays several DataGridViews in the following layout:
(No access to image hosting at work, so please pardon the ASCII art...)┌─────────────────────────────────────────┐
│┌───────────┐┌──────────────────────────┐│
││ ││ ││
│└───────────┘│ ││
|┌───────────┐│ ││
││ ││ ││
│└──────开发者_Python百科─────┘│ ││
|┌───────────┐│ ││
││ ││ ││
│└───────────┘└──────────────────────────┘│
└─────────────────────────────────────────┘
Unfortunately, when the user resizes the form to be taller, the form ends up looking like this:
┌─────────────────────────────────────────┐
│┌───────────┐┌──────────────────────────┐│
││ ││ ││
│└───────────┘│ ││
| | ||
| | ||
|┌───────────┐│ ││
││ ││ ││
│└───────────┘│ ││
| | ||
| | ||
|┌───────────┐│ ││
││ ││ ││
│└───────────┘└──────────────────────────┘│
└─────────────────────────────────────────┘
Instead of this:
┌─────────────────────────────────────────┐
│┌───────────┐┌──────────────────────────┐│
││ ││ ││
││ ││ ││
│└───────────┘│ ││
|┌───────────┐│ ││
││ ││ ││
││ ││ ││
│└───────────┘│ ││
|┌───────────┐│ ││
││ ││ ││
││ ││ ││
│└───────────┘└──────────────────────────┘│
└─────────────────────────────────────────┘
To reproduce this, anchor the Top-Left DataGridView to Top-Left, the Center-Left DataGridView to Left, and the Bottom-Left DataGridView to Bottom-Left, and the big DataGridView to all 4.
What can I do to get the behavior I want?
Put a TableLayoutPanel in the left hand column with 3 rows and 1 column, dock each of the smaller controls in a row with docking stlye "fill", then anchor the TableLayoutPanel left, top, and bottom.
Try using the some SplitContainer controls in combination with some Panel or GroupBox containers. Then your user will have the ability to size as needed also.
精彩评论