简体   繁体   中英

C# Winforms: Issue with controlling heights of controls inside group boxes

probably another noob question but I am trying to dynamically control the height of some group boxes as the form is resizing. However the listboxes inside the groupboxes (which are anchored to top and bottom) sometimes decide they want to shrink when the form is reduced in height. I have no idea how to fix, this please help!

private void Fluxx_Resize(object sender, EventArgs e)
{    
    groupBox1.Height = Height / 2 - 40;
    groupBox2.Height = Height / 2 - 40;
    groupBox3.Height = Height / 2 - 40;
    groupBox4.Height = Height / 2 - 40;
    groupBox3.Top = Height - groupBox3.Height - 51;
    groupBox4.Top = Height - groupBox4.Height - 51;
}

This seems to work perfectly when resizing the form vertically, but seems to randomly decide the recude the heights of the listboxes contained inside the groupboxes to zero at somepoint. I can then expand the form vertically again and the listboxes still react, but they always start from zero height and wont stay anchored to the top and bottom of the group boxes.

Cheers, Tim

OK

So if I remove the ability for the controls to resize their width then the height never has an issue. here is the code for one of the blocks for the width resizing. I have no idea why this clashes.

groupBox1.Width = Width / 3 - 20;
listBoxPlayer1.Left = 6;
listBoxPlayer1.Width = groupBox1.Width / 2 - GAP / 3;
listBoxKeepers1.Width = listBoxPlayer1.Width;
labelK1.Left = groupBox1.Width / 2 + SMALL_GAP;
listBoxKeepers1.Left = labelK1.Left;

Calculation of height and width couldn't support every condition,but you could use dock ,if you divide your form in to sections that have container ,you could set every container :

Dock = DockStyle.Fill

so your design will be compatible with each size of form.

Setting all of the listboxes inside of my groupboxes IntegralHeight to false was able to fix my issue. Cheers everyone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM