Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说C# SuspendLayout()和ResumeLayout(),希望能够帮助你!!!。
Temporarily suspends the layout logic for the control.
Namespace:
System.Windows.Forms
Assembly:
System.Windows.Forms
(in System.Windows.Forms.dll)
public void SuspendLayout()
The layout logic of the control is suspended until the ResumeLayout method is called.
The SuspendLayout and ResumeLayout methods are used in tandem to suppress multiple Layout events while you adjust multiple attributes of the control. For example, you would typically call the SuspendLayout method, then set the Size, Location, Anchor, or Dock properties of the control, and then call the ResumeLayout method to enable the changes to take effect.
There must be no pending calls to SuspendLayout for ResumeLayout to be successfully called.
Note |
---|
When adding several controls to a parent control, it is recommended that you call the SuspendLayout method before initializing the controls to be added. After adding the controls to the parent control, call the ResumeLayout method. This will increase the performance of applications with many controls. |
The following code example adds two buttons to a form. The example transactions the addition of the buttons by using the SuspendLayout and ResumeLayout methods.
private void AddButtons() { // Suspend the form layout and add two buttons. this.SuspendLayout(); 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(); }
今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
上一篇
已是最后文章
下一篇
已是最新文章