zoukankan
html css js c++ java
挖一下 SuspendLayout, ResumeLayout 的原理
最近看到一些 winform 控件的写法里面,在设定 DockStyle 或者增减子控件的时候,往往先调用 SuspendLayout 方法,操作完毕之后调用一下 ResumeLayout. 不太明白其中的道理。所以用 Reflector 来看一下。
代码在 System.Windows.Forms.Control 中。
做一个简单的记录如下:
public
void
SuspendLayout()
{
this
.layoutSuspendCount
=
(
byte
) (
this
.layoutSuspendCount
+
1
);
}
public
void
ResumeLayout()
{
this
.ResumeLayout(
true
);
}
public
void
ResumeLayout(
bool
performLayout)
{
if
(
this
.layoutSuspendCount
>
0
)
{
this
.layoutSuspendCount
=
(
byte
) (
this
.layoutSuspendCount
-
1
);
if
(((
this
.layoutSuspendCount
==
0
)
&&
((
this
.state
&
0x200
)
!=
0
))
&&
performLayout)
{
this
.PerformLayout();
}
}
if
(
!
performLayout)
{
Control.ControlCollection collection1
=
(Control.ControlCollection)
this
.Properties.GetObject(Control.PropControlsCollection);
if
(collection1
!=
null
)
{
for
(
int
num1
=
0
; num1
<
collection1.Count; num1
++
)
{
Control.LayoutManager.UpdateAnchorInfo(collection1[num1]);
}
}
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public
void
PerformLayout()
{
this
.PerformLayout(
null
,
null
);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public
void
PerformLayout(Control affectedControl,
string
affectedProperty)
{
if
(
!
this
.GetAnyDisposingInHierarchy())
{
if
(
this
.layoutSuspendCount
>
0
)
{
this
.state
|=
0x200
;
}
else
{
this
.layoutSuspendCount
=
1
;
try
{
this
.OnLayout(
new
LayoutEventArgs(affectedControl, affectedProperty));
}
finally
{
this
.state
&=
-
513
;
this
.layoutSuspendCount
=
0
;
}
}
}
}
查看全文
相关阅读:
AGC 014 B
AGC 012 D
AGC 012 C
python
Linux
Linux
Linux
Linux 之 光标消失隐藏术
Linux
python
原文地址:https://www.cnblogs.com/RChen/p/161379.html
最新文章
Educational Codeforces Round 36
Codeforces Round #453 (Div. 1)
Codeforces Round #454 (Div. 1)
maven学习之pom.xml或settings.xml对nexus的配置(转)
linux下部分软件截图
maven 配置篇 之 settings.xml
Maven2的配置文件settings.xml
详解java定时任务
spring boot实战(第十二篇)整合RabbitMQ
Grunt Bower构建前端
热门文章
dubbo控制器xml文件报错
手把手教你提交文件到git
git链接到远程github上
CodeForces
CodeForces
CodeForces
HihoCoder
CodeForces
CodeForces
AGC 026 C
Copyright © 2011-2022 走看看