pinkpig Posted March 25, 2008 Posted March 25, 2008 (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 March 25, 2008 by pinkpig Quote
techmanbd Posted March 25, 2008 Posted March 25, 2008 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"); } } Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
pinkpig Posted March 25, 2008 Author Posted March 25, 2008 (edited) Hello, techmanbd. Thanks!!, at first i didnt get it to work and posted the problem. But now its working!. Thank you!. Edited March 25, 2008 by pinkpig Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.