Search code examples
c#imagetabpage

C# TabPage ImageKey not drawing


I have an Application that runs tests on a customers account in order to judge if their service is working correctly. During the process of running the tests, the application reads each test and checks to see if it passes / fails / etc... It plays a green checkmark / red x on the tabPage itself as an imagekey... the imagekey is assigned as so

(tabPage as TabPage).ImageKey = "pass.png";

tabPage is actually an object that is passed through to the function so i can refer to it from a different method.

When the tabControl for the tabPage is created (dynamically), an imageList is added to the tabControl (which is where the images are pulled from).

(tabControl[0] as TabControl).ImageList = imageList2;

So when the method finally gets around to the code to assign the ImageKey it does run through the code, however it just shows up as a blank image. It's weird, because it works for some people and not others. It does not currently work on mine atm either and they do not show when I execute the source code. Does anyone have any ideas? Here's an image to help describe the issue... More code to follow if needed. Example Image


Solution

  • Your need for an answer has probably long-since passed, but I had the same problem, and here is my solution:

    Setting the ImageKey does not work, but setting the ImageIndex does cause the icon to display. I made an enumerator that mapped the icons to their indices.

    private enum TabIconCodes : int
    {
        Stopped = 1,
        Running = 2,
    }
    unitTab.ImageIndex = (int)TabIconCodes.Stopped;
    

    This is not an ideal solution, but it does work.