C # Winforms: GroupBox doesn't resize

I have two GroupBoxes on the left side of one of my TabControls , name them GroupBox A (top left) and GroupBox B (bottom left). Group boxes do not change, as I hope.

Example: When I resize the main form with TabControls using the mouse or enlarge it or move it to a lower resolution screen, GroupBox B retains its width / height. This causes GroupBox B to draw over GroupBox A, sort of like the โ€œalways on topโ€ effect.

Desired: It is desirable that both GroupBoxes resize relative to each other / proportionally and correspond to the area they gave.

Ideas?

+6
source share
5 answers

The LayoutPanel table can help with this.

  • Add a LayoutPanel table and place it according to your needs.
  • Snap the table to the top, bottom, left, and right.
  • Place GroupBoxA in the upper left cell of the table
  • Place GroupBoxB in the lower right cell of the table
  • For both GroupBox, their size is accordingly and binds them to all 4 sides.
  • Now they will grow and contract in proportion to the application.

In addition, you can add more controls to the table. If you need a control to span multiple rows or columns, use the RowSpan / ColumnSpan property.

+6
source

If your GroupBox is inside another control, such as a tab or something else, follow these steps:

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

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

And if you have several group boxes, you need to set the binding accordingly.

+2
source

I ran into a similar problem, I just used a separation container for GroupBoxes, tied the separation container at the top, bottom, left to the right of my main form, and both GroupBox also at the top, bottom, left and right of their containers.

+1
source

A little off topic from the original question, but my problem was that my MaximumSize field of my group mailbox was not set or was too small, so I could not change the height size!

+1
source

Most likely, the question is quite old, someone else might find it useful ... I had the same problem and I found a working solution -> instead of changing the width / height of the GroupBox, changed its minimum width / height in the resize method

edit: fixed typo

  private void Form1_Resize(object sender, EventArgs e) { groupBox1.MinimumSize = new Size(this.Width /2, this.Height); } 
+1
source

Source: https://habr.com/ru/post/952394/


All Articles