how to get ancestor's type?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I can check if a control is inherited from TabControl like this:

if (c.GetType().ToString() == "System.Windows.Forms.TabControl")

But what if c is inherited from TabControl? How to check that?

Thank you
 
Alex K. said:
I can check if a control is inherited from TabControl like this:

if (c.GetType().ToString() == "System.Windows.Forms.TabControl")

But what if c is inherited from TabControl? How to check that?

The operator "is".

if (c is System.Windows.Forms.TabControl )
{
}


David
 
Alex K. said:
I can check if a control is inherited from TabControl like this:

if (c.GetType().ToString() == "System.Windows.Forms.TabControl")

But what if c is inherited from TabControl? How to check that?

That's a really bad way of checking - and it's what the is and as
operators are for:

if (c is TabControl)
{
....
}

or

TabControl tc = c as TabControl;
if (tc != null)
{
...
}
 
Back
Top