Home > DeveloperSection > Forums > C# winform change selected tabcontrol image
john rob

Total Post:108

Points:756
Posted on    May-13-2013 3:48 AM

 C# C# 
Ratings:


 1 Reply(s)
 2220  View(s)
Rate this:
Hi Expert!

I have a winform application written in C#. I had an imageList in my winform and I have a tabcontrol and each of the tab I assign a image as icon for the tab by 

changing ImageIndex.

However they have only 1 image for each tab and I want them to change to another image for the selected tab (like another highlighted image for active one). I have an 

idea to add all images to the imageList (both active and inactive images) and change the imageIndex of the selected tab. But I am not sure how to do it in practical.

Here are my current codes that I can come up with:

Inside SelectedIndexChange event, I have a function:

foreach (TabPage tab in tabControl1) 
{
    if (tab.index == tabControl1.SelectedIndex) { <---how to get the index?
        tab.imageIndex = tab.index + tabControl1.TabCount;
    } else {
        tab.imageIndex = tab.index;
    }
}

Thanks in advance! 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-13-2013 9:38 AM

Hi John!

You can try as following

for (int i=0; i<tabControl1.TabPages.Count; i++)
        {
            if (tabControl1.TabPages[i] == tabControl1.SelectedTab)
            {
                tabControl1.TabPages[i].ImageIndex = i + tabControl1.TabPages.Count;
            }
            else
            {
                tabControl1.TabPages[i].ImageIndex = i;
            }
        }

I hope it helpful to you!


Don't want to miss updates? Please click the below button!

Follow MindStick