I am trying to build a web browser in Windows form application.I added an option of closing the tab in the contextmenu. I don’t want the tabpage to be selected on right click, just the context menu needs to appear. That works fine. The problem is when I click close tab the previous tab is closed and not the current one as previous tab is the one which was selected. I tried to figure this out by getting the rectangle location of the tabpage but that appears to be the same for all the tabs. Please help!
//this is my event handler for closing the tab
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.tabControlBrowser.TabPages.Remove(this.tabControlBrowser.SelectedTab);
}
Yest you are correct that is because you are using
this will remove the current selected tab but not the tab page that you are clicking on.
Please try below code hope it will help you to move forward