Click here to Skip to main content
13,042,630 members (79,536 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello friends,

I am working in a window Application. There is two group box in form and each group box has a grid view. My need is when I click on Maximum button of form then Both Group box and control inside group box should also increases and fit in form equally without no gap.
But when I am maximize the size it increases group box but there is a gap between two .

private void Form1_Resize(object sender, EventArgs e)
           if (this.MaximizeBox)
               groupBox1.Dock = DockStyle.Left;
               groupBox2.Dock = DockStyle.Right;

Please tell me how to solve this?

Thanks in Advance
Posted 6-Apr-13 3:48am
Updated 6-Apr-13 4:10am
Kenneth Haugland 6-Apr-13 10:10am
I assumed WinForms so I updated the Tag.
Neetesh Agarwal 6-Apr-13 10:13am
Thanks a lot Sir.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Instead of using Dock left and Dock right, fill your form with a Splitter, and dock each control in a panel each side.
Reduce the SplitterWidth property to 1, and set IsSplitterFixed to true.
Then handle the Splitter.Resize Event and set the SplitterDistance to half the width. (You will also want to do this in the form Load or Shown event as well.
It will work a lot better than docking left or right, which expects a centre area for other controls.

(You can also do this by setting the controls in place manually in the designer and setting the Anchor properties correctly, but that gets kinda messy to work out with more than two controls)
Neetesh Agarwal 6-Apr-13 10:13am
Thanks Sir..........
OriginalGriff 6-Apr-13 10:32am
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 6 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100