The main form has added a panel(from now called "imagePanel") to itself.
The panel is automatically stretched by some elements on the top and on the left side.
Autoscroll is true, so i can scroll around in the panel.
Here is my problem: When i scroll down or sideways on the panel, the image is always THERE. e.g: I have scrolled down to y=1000 and x=0, and i KNOW that the image is drawn on 256,256. But still the image is shown on the screen.
What i do:
imagePoint is an object which holds x and y coordinates. I have loaded some images into a Hashtable where:
Key = imagePoint, value = Bitmap
This is my OnPaint on panel:
private Bitmap backBuffer = null;
private void imagePanel_Paint(object sender, PaintEventArgs e)
{
// Make a new back buffer if needed.
if (backBuffer == null)
{
backBuffer = new Bitmap(this.imagePanel.Width, this.imagePanel.Height);
}
Hashtable images = ImageActions.getDownloadedImages();
using (Graphics g = Graphics.FromImage(backBuffer))
{
g.Clear(Color.White);
foreach (DictionaryEntry item in images)
{
// If we have an image, draw it
if (null != item.Value)
{
ImagePoint coordinates = (ImagePoint)item.Key;
int x = coordinates.getX();
int y = coordinates.getY();
g.DrawImage((Bitmap)item.Value, x, y);
}
}
g.Dispose();
}
e.Graphics.DrawImage(backBuffer, 0, 0);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// Don't allow the background to paint.
}
Hope someone can help me with this, since it works by using lots of pictureboxes, but it would be more efficient by drawing the images directly on the panel.
Thanks in advance