Re: Getting the TabPage of a control...




"JamesB" <jame@xxxxxxxxxxxxxxxx> wrote in message news:4892c7f1$0$26093$db0fefd9@xxxxxxxxxxxxxxxxx
I am trying to find the tab page a certain control is on.
Basically I'm using the MSRDP ActiveX Control. On the "disconnect" event, I want to then remove the TabPage that the relevant RDP session lived in. So, I have the following code:

void _tsClient_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)
{
AxMSTSCLib.AxMsRdpClient6NotSafeForScripting _dClient = (AxMSTSCLib.AxMsRdpClient6NotSafeForScripting)sender;
//get container.
TabPage _clientTab = (TabPage)_dClient.Container;
tabSessions.TabPages.Remove(_clientTab);
}

However, _clientTab is always null... I saw ContainingControl, however that won't compile as it says it cannot convert Type "System.Windows.Forms.ContainerControl' to 'System.Windows.Forms.TabPage'.

Any ideas?


OK - i've come up with a workaround, seems fine but not sure it's "correct" -

When I create the new tabpage + rdp session control, I am setting the Tag property of the RDP session to my new tab. Then, in the code above, I replaced "Container" with "Tag", and now my tab disappears when the session is closed.

Like I say- works, but seems a bit of a kludge...

James

.


Loading