Using inner controls from a tab page control

  • Thread starter Thread starter pnp
  • Start date Start date
P

pnp

I have a tab control and in each tab a custom control. All the custom
controls (different amongst them) have a common function.
What I want to do is when a user clicks on a tab, I want the function of the
control in the tab page to be called. Is there a way to do this without
using a switch statement or an if statement?

Something like this.Tab_Management.SelectedTab.Controls[0] ...
 
Have all of your custom controls implement an interface that contains
the method you want to call when a tab is clicked. You can then loop
through a tab's controls after a click and find the one that implements
your interface.

Something like this (untested) code...

foreach( Control c in targetTab.Controls )
{
if( c is IMyTabControl )
{
IMyTabControl myTabCtl = c as IMyTabControl;
myTabCtl.MyMethod();
}
}

Regards,
-Jeff
 
Back
Top