Tab Control Events Not Firing
-
Using C# in a Winform, I have a tab control with 2 tabs... I added methods for Enter and Leave events for tabpage1, but the events never fire when I switch tabs... breakpoints in these methods are never hit... what am I forgetting or doing wrong...??? thanks.
-
Using C# in a Winform, I have a tab control with 2 tabs... I added methods for Enter and Leave events for tabpage1, but the events never fire when I switch tabs... breakpoints in these methods are never hit... what am I forgetting or doing wrong...??? thanks.
The Enter and Leave events are for the TabPage not the TabControl. Once you switch Tabs if you click in the TabPage your event will fire. If you want to do something when the TabControl switches pages it's best to put the code in the SelectedIndexChanged event of the TabControl. Hope that helps. - monrobot13
-
Using C# in a Winform, I have a tab control with 2 tabs... I added methods for Enter and Leave events for tabpage1, but the events never fire when I switch tabs... breakpoints in these methods are never hit... what am I forgetting or doing wrong...??? thanks.
Use toolbox to drop a tab control onto the form; use the tab properties menu (Tab Pages - collection) to create one, or more tab pages and their labels; Right click in the whichever is topmost in the control - you will note that right clicking the mouse within the tab control's page(s) will bring up the properties (or events) menu for the Tab pages - can't set event handlers here - what you have to do is to then left click on one of the tabs - you will see that the properties (or events) menu for the Tab Control is now displayed (see note 1 below). You can now create event handlers for "Enter" and "Selected Index Changed" to give you the notifications you will most likely want to use use in your code - the "Enter" event occurs when the tab control (regardless of whichever page is topmost) receives the focus; the "Selected Index Changed" event occurs when you click on a tab different than the one that is currently topmost. Note 1: If you are displaying a Tab Page's properties (or events) menu (say for page 2) and you then left click on the page 2 tab to switch to the Tab Control menus you may find that it won't switch - have no fear, simply left click on a different tab. If you have a one tab control then click on the blank space immediately to the right of the tab. A VERY simple example of a do-nothing "Selected Index Changed" event handler is: private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e) { int index=tabControl1.SelectedIndex; // Tab Control's tab index (0 relative) int tabIndex=tabControl1.TabIndex; // KB tab-key order string str = String.Format("tabControl2_SelectedIndexChanged selectedIndex={0} tabIndex={1}", index,tabIndex); MessageBox.Show(str); } Hope this helps. Spolia Opima