我继承了一个Label,但是我想它被拖动窗口的设计界面时AutoSize不被设为真,如何做到?我的做法是重写AutoSize,把base.AutoSize等于false。这样做可失去了AutoSize的作用,反编译查了Label,查看所有设计器,也不知道微软是怎样自动把AutoSize设计为True的。

解决方案 »

  1.   

    AutoSize默认就是false,都不需要重写它,就是false。
      

  2.   

     class Mylabel:Label
        {
            protected override void CreateHandle()
            {
                this.AutoSize = false;
                base.CreateHandle();
            }
            
        }
      

  3.   

    public class MyLabel : Label
    {
        protected override void InitLayout()
        {
            base.InitLayout();
            AutoSize = false;
        }
    }