Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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

Edited by pinkpig
Posted

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

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:

 

private void TabControl1_SelectedIndexChanged(Object sender, EventArgs e)
{
if(TabControl1.SelectedTab == this.tabpage2)
		{
			MessageBox.Show("Selected tab2");
		}
}

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted (edited)

Hello, techmanbd.

Thanks!!, at first i didnt get it to work and posted the problem. But now its working!. Thank you!.

Edited by pinkpig

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...