I am using TabControl_SelectedIndexChanged
event when the user change tabs. The TabControl.SelectedIndex
/ TabControl.SelectedTab
return only the new tab. Is there any way I can get the previous tab? Or must I stick with the obvious store the current tab every time I change tabs?
I want to use this to cancel a change of tabs under certain conditions, like there is unsaved changes.
If you want to cancel the change of a tab, you can use the Deselecting
event. There you can cancel the change by setting property Cancel
of the provided TabControlCancelEventArgs
to true.
Check out http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.selected%28v=vs.80%29.aspx
There are events better suited for what you want to do.
I used tabControl Selected method to prevent users selecting a certain tab, in other word, to disable a tab page.
TabPage currentPage;
private void tabControl1_Selected(object sender, TabControlEventArgs e)
{
if (e.TabPage == tabNotAllowed)
{
tabControl1.SelectedTab = currentPage;
MessageBox.Show("You cannot use the tab you selected.");
}
else
{
currentPage = e.TabPage;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With