SuspendLayout 和 ResumeLayout
http://hi.baidu.com/zouqiner/blog/item/a6118b4aa92391f982025ce9.html
http://www.cnblogs.com/badnewfish/archive/2007/01/19/624298.html
临时挂起控件的布局逻辑。
命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)
语法:
备注:
控件的布局逻辑被挂起,直到调用 ResumeLayout 方法为止。
当调整控件的多个属性时,将先后使用 SuspendLayout 和 ResumeLayout 方法取消多个 Layout 事件。例如,通常先调用 SuspendLayout 方法,然后设置控件的 Size、Location、Anchor 或 Dock 属性,最后调用ResumeLayout 方法以使更改生效。
SuspendLayout 调用必须等于零,然后才能成功调用 ResumeLayout。
将多个控件添加到父控件时,建议在初始化要添加的控件之前调用 SuspendLayout 方法。将控件添加到父控件之后,调用 ResumeLayout 方法。这样就可以提高带有许多控件的应用程序的性能。
下面的代码示例向窗体添加两个按钮(3个哦,其中一个是w)。该示例通过使用 SuspendLayout 和 ResumeLayout方法进行添加按钮。
this.SuspendLayout();
Button buttonOK = new Button();
buttonOK.Location = new Point(10, 10);
buttonOK.Size = new Size(75, 25);
buttonOK.Text = "OK";
Button button1 = new Button();
button1.DialogResult = DialogResult.OK;
Controls.Add(button1);
Button buttonCancel = new Button();
buttonCancel.Location = new Point(90, 10);
buttonCancel.Size = new Size(75, 25);
buttonCancel.Text = "Cancel";
this.Controls.AddRange(new Control[]{buttonOK, buttonCancel});
this.ResumeLayout();
}
浙公网安备 33010602011771号