我的意图是表单大小足以显示整个"buttonOK",但不会大得多.实际发生的是,调整大小的表格最终会变小,甚至根本不显示按钮.
public MyFormDlg()
{
InitializeComponent();
this.Height = this.buttonOK.Bounds.Bottom + SomePadding;
Run Code Online (Sandbox Code Playgroud)
该Height属性包括Window标题栏的高度,因此客户区(按钮边界相对于该区域)小于您的预期.
这有效:
this.ClientSize = new Size(this.ClientSize.Width,
this.buttonOK.Bounds.Bottom + SomePadding);
Run Code Online (Sandbox Code Playgroud)
我没有找到ClientHeight房产,这可以做得更简单吗?