I have a form with a layout control divided in three parts, left, mid and right. By default, the right layout control item (which has a couple of grids) is hidden. There’s a button in the form that expands the form to the right to show the two grids. When you click the button again, it hides the right layout control item and changes the size of the form again. The basic functionality is working fine, but I would like to also update the MinimumSize when the user presses the button (so while the form is expanded, the minimum width should be increased). This is my current code:
private void btnExpand_Click(object sender, EventArgs e)
{
this.SuspendLayout( );
switch (lciRight.Visibility)
{
case LayoutVisibility.Never:
LoadGrids();
lciRight.Visibility = LayoutVisibility.Always;
this.Width += lciRight.Width;
this.MinimumSize = new Size(this.Width, this.MinimumSize.Height);
btnExpand.Text = "<<";
break;
case LayoutVisibility.Always:
lciRight.Visibility = LayoutVisibility.Never;
this.MinimumSize = new Size(689, this.MinimumSize.Height);
this.Width -= lciRight.Width;
btnExpand.Text = ">>";
break;
default:
break;
}
this.ResumeLayout();
}
The problem I’m having is that when the form is already expanded and we click on the button to make it the original size again, the
this.MinimumSize = new Size(689, this.MinimumSize.Height);
line is not updating the MinimumSize correctly. Any idea why?
This is pretty straightforward function.
Please consider that you should check changes to this property (and any other relevant to layout) after the following line is executed:
Reason is –
SuspendLayout()suspends all changes to control layout to increase performance of your application.If property still hasn`t changed you most probably override it (set width to 1100) somewhere else