Tabcontrol help.

pinkpig

Newcomer
Joined
Mar 25, 2008
Messages
2
Hello all, im new to .NET C# programming.
Im experimenting with tabcontrol now.
I created a tabcontrol with two tabs. I want to be able to do some stuff after i change tabs.I want to capture that i clicked on tabpage2 and execute some code and then show tabpage2. How do i go about doing that? I've tried by putting this code in my Form1.cs. But when run the application and switch tabs, nothing happens.

private void TabControl1_SelectedIndexChanged(Object sender, EventArgs e)
{

MessageBox.Show("You are in the TabControl.SelectedIndexChanged event.");

}

Any help would be great!.
Thanks
Laura
 
Last edited:
Hello Laura and welcome to the forum.

I don't see why you are not getting the message box to show up. The only thing I can think of is look in the region "Windows Form Designer generated code" and find your TabControl1 area where it initializes and look to see if the handle is there for that method.

It should look something like this
C#:
this.tabInfo.SelectedIndexChanged += new System.EventHandler(this.tabInfo_SelectedIndexChanged);

Also to answer your other question. If you are selecting a tab from that tab control. Look for for the selected tab like so:

C#:
private void TabControl1_SelectedIndexChanged(Object sender, EventArgs e)
{
if(TabControl1.SelectedTab == this.tabpage2)
			{
				MessageBox.Show("Selected tab2");
			}
}
 
Hello, techmanbd.
Thanks!!, at first i didnt get it to work and posted the problem. But now its working!. Thank you!.
 
Last edited:
Back
Top