发布时间:2025-12-10 19:21:16 浏览次数:8
C# SuspendLayout()和ResumeLayout()「终于解决」Temporarilysuspendsthelayoutlogicforthecontrol.Namespace: System.Windows.FormsAssembly: System.Windows.Forms (inSystem.Windows.Forms.dll)SyntaxC#C++
Temporarily suspends the layout logic for the control.
Namespace: System.Windows.Forms
publicvoidSuspendLayout()
是否还在为Ide开发工具频繁失效而烦恼,来吧关注以下公众号获取最新激活方式。亲测可用!
【正版授权,激活自己账号】:Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】:官方授权 正版激活 自己使用,支持Jetbrains家族下所有IDE…
RemarksThe layout logic of the control is suspended until theResumeLayoutmethod is called.
TheSuspendLayoutandResumeLayoutmethods are used in tandem to suppress multipleLayoutevents while you adjust multiple attributes of the control. For example, you would typically call theSuspendLayoutmethod, then set theSize,Location,Anchor, orDockproperties of the control, and then call theResumeLayoutmethod to enable the changes to take effect.
There must be no pending calls toSuspendLayoutforResumeLayoutto be successfully called.
| Note |
|---|
| When adding several controls to a parent control, it is recommended that you call theSuspendLayoutmethod before initializing the controls to be added. After adding the controls to the parent control, call theResumeLayoutmethod. 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 theSuspendLayoutandResumeLayoutmethods.
C# C++ VBprivatevoid 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();}