Search code examples
.netwinformsanchorpanelgroupbox

How to Anchor 3 GroupBox grow 2, 1 should be the same size


I want to anchor 3 GroupBox. First and third GroupBox, both contains only 1 DataGridView. Second GroupBox contains buttons and textboxes. First GroupBox should be to the left side of Panel, second GroupBox should be in center, third GroupBox should be right. First and Third GroupBox should be able to grow, second GroupBox need to keep position.

For second: GroupBox I anchor it to bottom and top. It keep position and grow only in Height - that' what I want.

For first and third GroupBox I don't have solution yet. I tried so many combination but I didn't find correct. enter image description here


Solution

  • Maybe it isn't the best solution but it worked for me. I used TableLayoutPanel.

    1. Add TableLayoutPanel to Main panel.
    2. Change property: ColumnCount to 3.
    3. Change property: RowCount to 1.
    4. You will have 3 boxes in TableLayoutPanel. In each Boxes add 1 GroupBox.
    5. Change Dock property for each GroupBox to Fill.
    6. Click on Edit Rows and Columns in TableLayoutPanel Tasks enter image description here
    7. Change Value and Size Type for each Column. In my case I put for first and third Column: Size Type = Percent, Value = 50. For second Column I put Size Type = AutoSize.

    So now I get what I want. Thanks to @levelonehuman who give me idea about Layouts.