Hi all!

I create a class named TabPageEx which extends TabPage.

In my app, sometimes it is necessary to get the selected tab from the TabControl ( I named this object as tcDataPanes) in order to add some controls.

I tried to cast from but it does not work.
Code:
            tabpage1 = new TabPageEx();
            tabpage1 = (TabPageEx)tcDataPanes.SelectedTab;
An InvalidCastExpection message appears at runtime.

All tabpages that were created are TabPageEx' type. Each tabPageEx object has a FlowLayoutPanel, and there is a method at TabPageEx which returns this container to my app.

What is wrong?

Thank you in advance!