I'm using images to show a sequence. For this I'm using image list and the code is

Graphics g = this.panel2.CreateGraphics();
            ImageList photoList = new ImageList();
            photoList.TransparentColor = Color.Blue;
            photoList.ColorDepth = ColorDepth.Depth32Bit;

            photoList.ImageSize = new Size(40, 40);
            Graphics g1 = this.panel2.CreateGraphics();
            Pen green = new Pen(Color.Green, 1);

            int j = 0, k = 0, count = 0, width = (panel2.Width - 80), lines = 0, count1 = 0; ;
            lines = textBox8.Lines.Count();

            foreach (string i in textBox8.Lines)

                if ((i.Trim() != "") && (i.Trim() != "E"))
                    if (k < width)
                        string h = "Domain_" + i + ".png";
                        Stream imgStream3 = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsApplication2.Resources." + h + "");
                        photoList.Images.Add(new Bitmap(imgStream3));

                        if (count1 == 0)
                            photoList.Draw(g, new Point(k = k + 10, j), count);
                            photoList.Draw(g, new Point(k = k + 55, j), count);
                        count1 = count1 + 1;
                        count = count + 1;

                        if (lines != count)
                            g1.DrawLine(green, new Point(k + 40, j + 20), new Point(k + 80, j + 20));
                        // Paint the form and wait to load the image




but the problem is, if I change the tab or change the size of the form and come back then I can't see the images, they just disappeared. Is there something I did wrong.

Any help would be great.

thanks in advance

I think a good place to start is by overriding the Paint method of the control. The Tab Control you are evidently using has TabPages and in the event listed for the TabPage is a "Paint" event. Find it in the event list under the VS properties tab and double click on it. A stub Paint method will be created. Within that Paint event handler you should probably place the code you show above. What this will do is cause the images to be repainted every time a Paint event is triggered. The paint event can be triggered in any number of ways, including switching tabs, resizing windows, or artificially (programmatically) by directly calling the Paint event handler in another part of the code or by invalidating a region (partial or full) of a window or control. Good luck.

Edited 4 Years Ago by joseph.a.mineo: misspelling

This question has already been answered. Start a new discussion instead.