睡到⑩②點
专注于ASP.NET Ajax

当调整控件的多个属性时,将先后使用 SuspendLayoutResumeLayout 方法取消多个 Layout 事件。例如,通常先调用 SuspendLayout 方法,然后设置控件的 SizeLocationAnchorDock 属性,最后调用 ResumeLayout 方法以使更改生效。

private void AddButtons()
{
   // Suspend the form layout and add two buttons.
   this.SuspendLayout();//控件的布局逻辑被挂起,直到调用 ResumeLayout 方法为止。
   Button buttonOK = new Button();
   buttonOK.Location = new Point(10, 10);
   buttonOK.Size = new Size(75, 25);
   buttonOK.Text = "OK";

   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();
}

大量添加控件时会提高效率

posted on 2007-04-14 14:04  睡到⑩②點  阅读(1082)  评论(0编辑  收藏  举报