Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
What this an event on tabcontrol when select each tabpages on indexchanged.. lang="sql">I want to handle it on each pages.
How to do it at this point: selected controlpage1 show image.. selected controlpage2 show image2..
Posted
Updated 22-Jan-14 22:57pm
v2

Try this: choose Event SelectedIndexChanged

C#
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (tabControl.SelectedIndex)
            {

                case 1: 
                { 
                     //Your Changes
                     break; 
                }
                case 2: 
                {
                      //Your Changes 
                      break; 
                }
            }

        }

I hope I could help.
 
Share this answer
 
Comments
ligroC 23-Jan-14 6:33am    
Thanks for your reply.. it works!
Member 10497425 5-Feb-14 11:35am    
No problem
C#
private void TabControl1_SelectedIndexChanged(Object sender, EventArgs e) 

{

   MessageBox.Show("You are in the TabControl.SelectedIndexChanged event.");
    
}
So how to determine tabpages1 selected?
 
Share this answer
 
v2
use selected index changed event as follows:-

C#
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            MessageBox.Show("This is " + tabControl1.SelectedTab.Name);
        }
 
Share this answer
 
Comments
ligroC 23-Jan-14 4:53am    
I want to handle it on each pages.
How to do it at this point: selected controlpage1 show image.. selected controlpage2 show image2..
RhishikeshLathe 23-Jan-14 4:57am    
use tabControl1.SelectedTab.Name property to identify selected tab.
ligroC 23-Jan-14 5:00am    
Can you specify it more clearly with codes?
TabControl dynamicTabControl = new TabControl();
            dynamicTabControl.Name = "DynamicTabControl";
            dynamicTabControl.BackColor = Color.White;
            dynamicTabControl.ForeColor = Color.Black;
            dynamicTabControl.Font = new Font("Georgia", 16);
            dynamicTabControl.Width = 300;
            dynamicTabControl.Height = 200;

            TabPage tabPage1 = new TabPage();
            tabPage1.Name = "tabPage2";
            tabPage1.Text = "Author";
            tabPage1.BackColor = Color.Green;
            tabPage1.ForeColor = Color.White;
            tabPage1.Font = new Font("Verdana", 12);
            tabPage1.Width = 100;
            tabPage1.Height = 100;
            dynamicTabControl.TabPages.Add(tabPage1);
            // Add TabPage2
            TabPage tabPage2 = new TabPage();
            tabPage2.Name = "tabPage2";
            tabPage2.Text = "Books";
            tabPage2.BackColor = Color.Orange;
            tabPage2.ForeColor = Color.White;
            tabPage2.Font = new Font("Verdana", 12);
            tabPage2.Width = 100;
            tabPage2.Height = 100;
            dynamicTabControl.TabPages.Add(tabPage2); 
 
Share this answer
 
I tried with switch like that:
C#
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)

        {
            switch (tabControl1.SelectedIndex)
            {
                case 1:
                    {
                       MessageBox.Show("tab 1.");
                      
                        Image test = Image.FromFile(@"C:\image\1.jpg");

                        this.layer1.BackgroundImage = test;

                        break;
                    }
                case 2:
                    {
                        MessageBox.Show("tab 2.");
                   break;
                    }
                case 3:
                    {
                        MessageBox.Show("tab 2.");

                        Image test2 = Image.FromFile(@"C:\image\2.jpg");
                        this.layer2.BackgroundImage = test2;
                    }
                    break;
           }          
         
                  }  


But it gets nothing when change index on tabcontrol...
 
Share this answer
 
Comments
CHill60 23-Jan-14 7:35am    
You need to stop posting further information as "solutions" - use the "Have a Question or Comment" link or update your original post using the "Improve Question" link
Member 10497425 23-Jan-14 11:56am    
Why does it not work?? What is wrong? What doesnt work? Do you see the MessageBox?
ligroC 26-Jan-14 22:15pm    
I solved.. thank you
Check this site to find your Event and here is also tutorial.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900