窗体form中加入个SplitContainer控件并把tabstop设置成false,用foreach (Control item in form.Controls)找到这个SplitContainer控件后,如果直接访问item.tabstop返回的竟是true,如果转换后访问((SplitContainer)item).tabstop,就能正确的返回false.
请问这到底是怎么回事呢?
请问这到底是怎么回事呢?
{
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());
((SplitContainer)item).tabstop 是 SplitContainer.TabStop
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
item.tabstop 是 Control.TabStop
要转化为显示类型才能取值