I have an issue with an image getting corrupted upon scroll in a panel.



Hello all. I've followed some very nice articles at c-sharp corner and
the code project to come up with an overlayed map image, with military
unit icons on top (as well as text demarking the division name). My
problem is that the images are so large ; I wanted to put them into a
panel for scrolling capabilities. My issue now is that after painting
the images (one on top of the other, etcetera), the image gets
corrupted and disappears upon scrolling within a panel.

Layout:

Form { pictureBox1 inside a Panel 1 }.

I am using the following code upon selecting a new map name in a
combobox3:

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
IniFile INI = new IniFile(@"c:\\data\TM.ini");

string MapFileDir = INI.IniReadValue("Main", "MapDir");

string MapName = INI.IniReadValue("Main",
this.comboBox3.Text);

string[] MapNameArray = MapName.Split(',');
string ImageName = MapNameArray[0].ToString();

//pictureBox1.ImageLocation = MapFileDir + @"\"+ImageName;

Graphics g = pictureBox1.CreateGraphics();
g.Clear(this.BackColor);
Image curImage = Image.FromFile(MapFileDir + @"\" +
ImageName);
Image curImage2 =
Image.FromFile(@"c:\data\maps\G-Armour-mil.gif");
g.DrawImage(curImage, 0, 0, curImage.Width,
curImage.Height);
g.DrawImage(curImage2, 100, 100, curImage2.Width,
curImage2.Height);
SolidBrush mySolidBrush = new SolidBrush(Color.Black);
g.DrawString("1st", new Font("Verdana", 8), mySolidBrush,
new RectangleF(100, 89, 105, 98));
g.Dispose();
}

It works fine, and draws the images and text appropriately, but the
pictureBox1 is inside a panel1 for scrolling purposes. When I scroll
the panel, the image corrupts. Is there a way to redraw the image/s as
the panel is scrolling and keep appropriate x,y pixel overlays?

Here is a picture of the working program:

http://seow.trianglesimsociety.org/Captured.JPG

When i scroll the image using the scroll bars, the image corrupts, but
the icon stays in it's appropriate place. In other words, I'm only able
to draw into the visible area. If I move out of that initial visible
area, the image crops off and or disappears entirely.

My thoughts:
If there is no way around this picturebox in a panel redraw issue ;
then Im thinking of making an entirely new JPG out of the combination
of everything I've created above. Is there a way to do that invisibly,
save the file to a new name, then set the pictureBox1.imagelocation to
that new file? I may want this functionality anyhow after the final
mission template is created. Just FYI, in case you are wondering what
this is for ; This is for use as a template maker for the following
open source tool http://seow.sourceforge.net/

Thanks for any pointers you may be able to provide on this. I'm really
loving programming in c#. Its gotten me excited to program again.

Regards,
Peter Robbins
Freelance Programmer C#/PHP

.



Relevant Pages

  • Re: Flowlayout, JPanel and JScrollPane: Scrolling vertically impossible?
    ... >> JScrollPane using FlowLayout. ... >> enable wrapping, and when components inside the panel go out of view, ... > scrolling). ... > (And therefore the preferredSize value returned by the panel would ...
    (comp.lang.java.gui)
  • Re: Dialog Management Scrolling WAS Left & Right Scrolling in ISPF
    ... Making the panel width larger than 80 characters will cause an error if someone attempts to display the panel on a regular 80 width screen size. ... Dialog Management Scrolling WAS Left & Right Scrolling in ISPF ... My thought was that I would have to build a Panel table larger than the traditional 80 Character width. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: I have an issue with an image getting corrupted upon scroll in a panel.
    ... The GDI+ FAQ shows you how to save without compression. ... corrupted and disappears upon scrolling within a panel. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: I have an issue with an image getting corrupted upon scroll in a panel.
    ... the code project to come up with an overlayed map image, ... corrupted and disappears upon scrolling within a panel. ... If there is no way around this picturebox in a panel redraw issue; ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Drawing Lines on specific panel
    ... the problem is that my form heightis smaller then my panel height, so i have to scroll the panel up and down to see all it's content. ... As has been mentioned, in the Windows display paradigm requires that you always respond to the Paint event, drawing your image each time. ... it sounds as though you are having trouble with the scrolling aspect of the drawing. ... You can address this either by using the Panel's AutoScrollPosition property to offset your own drawing, or you can just "nest" your custom-drawn Panel inside a different Panel ...
    (microsoft.public.dotnet.languages.csharp)