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

     
    [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;
                      }

                }

          }

    }

     

  • 相关阅读:
    Android 解决小米手机Android Studio安装app 报错的问题It is possible that this issue is resolved by uninstalling an existi
    Android Unresolved Dependencies
    Android studio 自定义打包apk名
    Android Fragment与Activity交互的几种方式
    魅族和三星Galaxy 5.0webView 问题Android Crash Report
    Android几种常见的多渠道(批量)打包方式介绍
    Android批量打包 如何一秒内打完几百个apk渠道包
    上周热点回顾(9.30-10.6)团队
    上周热点回顾(9.23-9.29)团队
    上周热点回顾(9.16-9.22)团队
  • 原文地址:https://www.cnblogs.com/RChen/p/161379.html
Copyright © 2011-2022 走看看