Reset size of a control to its default
.net, c#, controls, size, winforms
Solution
You can use reflection to get the `DefaultSize` property of a control.
Size GetDefaultSize(Control ctrl)
{
PropertyInfo pi = ctrl.GetType().GetProperty("DefaultSize", BindingFlags.NonPublic | BindingFlags.Instance);
return (Size)pi.GetValue(ctrl, null);
}
myCtrl.Size = GetDefaultSize(myCtrl);
MSDN :
The DefaultSize property represents the Size of the control when it is initially created.
Problem
How do I reset he size of a control to its default in Windows Forms? I tried setting the size to (-1,-1), but that didn't work, though Height was getting set to default.