使用SuspendLayout和ResumeLayout
来源:互联网 发布:专业云计算服务提供商 编辑:程序博客网 时间:2024/05/21 19:37
使用 SuspendLayout 和 ResumeLayout
许多 Windows 窗体控件(例如,ListView 和 TreeView 控件)都实现了 SuspendLayout 和 ResumeLayout 方法,它们能够防止控件在添加子控件时创建多个布局事件。如果您的控件以编程方式添加和删除子控件或者执行动态布局,则您应该调用 SuspendLayout 和 ResumeLayout 方法。通过 SuspendLayout 方法,可以在控件上执行多个操作,而不必为每个更改执行布局。例如,如果您调整控件的大小并移动控件,则每个操作都将引发单独的布局事件。这些方法按照与 BeginUpdate 和 EndUpdate 方法类似的方式操作,并且在性能和用户界面稳定性方面提供相同的好处。下面的示例以编程方式向父窗体中添加按钮:
[C#]
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();
}
[Visual Basic .NET]
Private Sub AddButtons()
' Suspend the form layout and add two buttons
Me.SuspendLayout()
Dim buttonOK As New Button
buttonOK.Location = New Point(10, 10)
buttonOK.Size = New Size(75, 25)
buttonOK.Text = "OK"
Dim buttonCancel As New Button
buttonCancel.Location = New Point(90, 10)
buttonCancel.Size = New Size(75, 25)
buttonCancel.Text = "Cancel"
Me.Controls.AddRange(New Control() { buttonOK, buttonCancel } )
Me.ResumeLayout()
End Sub
每当您添加或删除控件、执行子控件的自动布局或者设置任何影响控件布局的属性(例如,大小、位置、定位点或停靠属性)时,您都应该使用 SuspendLayout 和 ResumeLayout 方法。
- 使用SuspendLayout和ResumeLayout
- 使用SuspendLayout和ResumeLayout
- SuspendLayout 和 ResumeLayout 方法
- SuspendLayout 和 ResumeLayout
- C# SuspendLayout()和ResumeLayout()
- WinForm-SuspendLayout、ResumeLayout、PerformLayou
- WinForm-SuspendLayout、ResumeLayout、PerformLayou
- ResumeLayout、SuspendLayout、PerformLayout
- 利用SuspendLayout 和 ResumeLayout 方法加速添加控件
- C#中窗体程序中的this.SuspendLayout()和this.ResumeLayout()
- suspendlayout,resumelayout,layout,performlayout【转】
- suspendlayout,resumelayout,layout,performlayout【转】
- Control.SuspendLayout 方法 ResumeLayout 方法 (Boolean)
- 挖一下 SuspendLayout, ResumeLayout 的原理
- C# WinForm中的SuspendLayout、ResumeLayout、PerformLayou
- WinForm-SuspendLayout、ResumeLayout、PerformLayou——转载
- 对WinForm-SuspendLayout、ResumeLayout、PerformLayout的理解
- WinForm-SuspendLayout、ResumeLayout、PerformLayou——转载
- [DCC Error] E2161 Error: RLINK32: Error opening file "_____.drf"
- Android之虚拟机慢的解决方案
- android开发-简单动画3
- 混音算法
- [ACM] hdoj1018 Big Number 解题报告
- 使用SuspendLayout和ResumeLayout
- Android之自定义checkbox样式
- 暑假集训——贪心专题——D题
- Android手机为什么不同GPU游戏兼容性差别巨大
- win32编程入门-子窗口控件
- Squares-暴力枚举或者二分
- java 反射浅析
- SqlServer 与 MySQL 基本操作语句对比
- p0j 2488 A Knight's Journey