You can use tabcontrol. selectedtab to read only the tabpage currently in use. The selectindexchanged command can only read the tabpage information of the tab when switching the tabpage tab.
You can click the left button to activate a tabpage, but you cannot right-click it. So how can we design it so that right-clicking can also obtain tabpage information? You can use the following Code :
Private Void Tabcontrol1_mousedown ( Object Sender, mouseeventargs E)
{
If (E. Button = Mousebuttons. Right)
{
This . Textbox1.text = "" ;
Point PT = New Point (E. X, E. y );
Rectangle rectl = New Rectangle ();
For ( Int I = 0 ; I < Tabcontrol1.tabcount; I ++ )
{
This . Textbox1.text + = " Widget " + I + " : \ R \ n " ;
Rectl = Tabcontrol1.gettabrect (I );
This . Textbox1.text + = Rectl. tostring () + " \ R \ n " ;
If (Rectl. Contains (PT ))
This . Textbox1.text + = PT. tostring () + " Belong " + " Widget " + I + " . " + Rectl. tostring () + " \ R \ n " ;
}
}
}
the code mainly obtains the coordinates when right-clicking, obtains the matrix size of each tabpage, and determines whether the right-clicking coordinates are in the Matrix to determine which tabpage is right-clicking.