窗体form中加入个SplitContainer控件并把tabstop设置成false,用foreach (Control item in form.Controls)找到这个SplitContainer控件后,如果直接访问item.tabstop返回的竟是true,如果转换后访问((SplitContainer)item).tabstop,就能正确的返回false.
请问这到底是怎么回事呢?

解决方案 »

  1.   

    没看过 SplitContainer的代码可能是            public class Test
            {
                public int a = 0;
            }        public class AAA : Test
            {
                public new int a = 1;
            }可能是这样的把    AAA a = new AAA();            Test b = (Test)a;            MessageBox.Show(a.a.ToString(), b.a.ToString());
      

  2.   

    SplitContainer.TabStop 覆盖了 Control.TabStop,不是override。直接访问item.tabstop 是 Control.TabStop
    ((SplitContainer)item).tabstop 是 SplitContainer.TabStop
      

  3.   

    虽然SplitContainer是继承自ContainerControl
    ContainerControl继承自ScrollableControl
    ScrollableControl继承自ControlControl里有个attribute:
    public bool TabStop { get; set; }SplitContainer自己本身也有个attribute:
    public bool TabStop { get; set; }这样会导致SplitContainer的TabStop覆盖掉Control的TabStop。例如:        class Father
            {
                public bool TabStop { get; set; }
            }        class Son : Father
            {
                public bool TabStop { get; set; }
            }        static void Main(string[] args)
            {
                Son son = new Son();
                son.TabStop = true;
                Father father = son;            Console.WriteLine(father.TabStop.ToString());
                Console.WriteLine(son.TabStop.ToString());
            }
    输出:
    false
    true
      

  4.   

    不转化
    item.tabstop 是 Control.TabStop 
    要转化为显示类型才能取值
      

  5.   

    看上去像用了new,当然.net默认同名方法出现在子类和父类上都是new.