tags:

views:

243

answers:

1

Hi.

I have a created a panel. This has autoscroll = true

At the start i added 6 pictureboxes that are 256x256 with images. I store the last picturebox location, so that i know where to put a new picturebox.

I also add a picturebox to the upper right of the panel(location(8744,8744)), so that the panel will stretch to 9000px.

Later on when i scroll around in the panel, i can push a button and add a picturebox to the panel. The problem is that when i set the location of the picturebox and add it to the panel, it comes out totally wrong, visually.

Code for adding more images.

private void addPictureBox(Point pixelCoordinates, Bitmap image)
{
        PictureBox pNewImage = new PictureBox();
        imagePanel.Controls.Add(pNewImage);

        pNewImage.Image      = image;
        pNewImage.Name       = "image_:" + pixelCoordinates.X + "_" + pixelCoordinates.Y;
        pNewImage.Location   = pixelCoordinates;
        pNewImage.Size       = new System.Drawing.Size(256, 256);
        pNewImage.Visible    = true;
        pNewImage.BackColor  = Color.White;

        imagePanel.Update();

}

If i debug and watches the panel, it says that the new picturebox has the location i set, but visually, it's not.

I have noticed that this is what really happens: The location of the picturebox is from where i have scrolled + location.X.

Anyone got an idea how i can fix this?

Thanks in advance.

+1  A: 

If the pictureboxes are being added after you have scrolled away from the coordinates 0,0 you may need to account for this by adding the scroll amount to pixelCoordinates. Try using imagePanel.VerticalScroll.Value and imagePanel.HorizontalScroll.Value in your calculations.

JYelton
i'll try that later again. I tried it yesterday, but i think i used the scrollbar values a bit after i had created the images. And that is obviously wrong. i'll save the scrollbar position in a hashtable with the downloaded image's pixelcoordinate, so that i can subtract the scrollbarposition from the pixelcoordinates of the image.