Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Winforms: GroupBox not resizing

I have two GroupBoxes on the left side of one of my TabControls, call them GroupBox A (top left), and GroupBox B (bottom left). The GroupBoxes do not resize like I would hope.

Example: When I resize the main form that has the TabControls with my mouse, or maximize it, or move it to a screen with lower resolution, GroupBox B keeps its width / height. This causes GroupBox B to draw over GroupBox A, kind of like a 'always on top' effect.

Desired: Would like both GroupBoxes to resize according to one another / proporitionally and fit the area they are given.

Ideas?

like image 845
scryptKiddy Avatar asked Aug 23 '13 21:08

scryptKiddy


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


2 Answers

A tableLayoutPanel can help with this.

  1. Add a tableLayoutPanel and size it to fit your needs.
  2. Anchor the table to Top, Bottom, Left, and Right
  3. Put GroupBoxA into the upper left cell of the table
  4. Put GroupBoxB into the lower right cell of the table
  5. For both GroupBox size them accordingly and anchor them to all 4 sides.
  6. Now they will grow and shrink proportionately with the app.

Additionally you can add more of your controls to the table. If you need a control to span multiple rows or columns use the RowSpan/ColumnSpan property.

like image 54
jmstoker Avatar answered Sep 23 '22 04:09

jmstoker


If your GroupBox is inside another control like a tab or something, then do as below:

In my case I had a GroupBox inside a tab and I called the below methods in the InitializeComponent() method to force the Groupbox to adjust to the tab size.

this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();

And If you have multiple GroupBoxes, you need set the anchoring accordingly.

like image 38
Satish Kumar Avatar answered Sep 21 '22 04:09

Satish Kumar