Click here to Skip to main content
11,922,641 members (55,327 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET
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 4:48am
Edited 6-Apr-13 5: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
Web04 | 2.8.151125.1 | Last Updated 6 Apr 2013
Copyright © CodeProject, 1999-2015
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