I am having troubles with setting my user control to automatically resize with the panel where it is created. When user is resizing a main form that contains the user control, the size of this user control does not change at all making for some poor user experience.
So far I tried following:
These attempts had no effect on the behavior of my user control:
CalcUserControl calcControl = new CalcUserControl(CountryId);
calcControl.Dock = DockStyle.Fill;
panelUserCtrl.Controls.Clear();
panelUserCtrl.Controls.Add(calcControl);
Any suggestions would be much appreciated.
Try setting the AutoSize properties to False.
Also, instead of calling Controls.Clear();, try disposing of the controls inside it, something like:
while (panelUserCtrl.Controls.Count > 0) {
panelUserCtrl.Controls[0].Dispose();
}
Otherwise, you are leaking memory since those removed controls would still exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With