如何在 Windows 窗体中将控件的大小重置为其默认值?
我尝试将大小设置为 (-1,-1),但这没有用,尽管高度设置为默认值。
最佳答案
您可以使用反射来获取控件的 DefaultSize
属性。
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.
关于c# - 将控件的大小重置为其默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13608961/