0

I am trying to draw a number of nearly identical Image with Graphics.DrawImage(), taken from a Bitmap, into a PictureBox docked into a Panel and Panel.AutoScroll has been set into True. I know they are supposed to clip when they are drawn outside the PictureBox bound (by i mean bound is the PictureBox's Width and Height) but let say i can redraw those images when the PictureBox is resized, but that is not my real problem.

//This is my code which draw 40 x 40 circle, node alike, bitmaps into PictureBox
private void ValButton_Click(object sender, EventArgs e)
{
    Graphics gr = picBox.CreateGraphics();
    for (int i = 0; i < 101; i++)
    {
        gr.DrawImage(nodeBmp, (imgDisplay.Width / 2) + (i * 20), 80);
    }
    gr.Dispose();
}

when i resize the Form, by stretching the Form or by Maximizing the Form, the PictureBox is resized but the image is left not changed, not moved and still clipped, and no ScrollBar shown There should be 100 circles there ^There should be 100 circles there, and yet no ScrollBar

I stretch the Window, Still no ScrollBar ^stretched the Window, Still no ScrollBar. The X and Y label down there shown the current Width and Height of the PictureBox

Also, i have tried to change the PictureBox.SizeMode to AutoSize and Normal still no change.

So, are the whole trial i have attempt wrong ? if so, what are the correct way to achieve ScrollBar for a Drawn images with Graphics ?

Thank you.

Tommy Aria Pradana
  • 574
  • 1
  • 4
  • 18
  • _Graphics gr = picBox.CreateGraphics();_ this will not work well: Neither will the result be persistent nor can it trigger a scrollbar. Only use the PaintArgs `e.Graphics` object from the `Paint` event!! See [here](http://stackoverflow.com/questions/8725326/how-to-make-use-of-autoscrollbar-when-drawing-contents-with-gdi) for a solution..! – TaW Nov 28 '16 at 18:54
  • @TaW Let's say that i have a method that handle Paint Event of my `picBox`, so then i should do all of my "drawing" with its `e.Graphics`, right ? – Tommy Aria Pradana Nov 28 '16 at 19:05
  • Right. Either directly in the Paint event or in methods to which you pass the e.Graphics object. But mind: Do not try to cache it, only use it triggered right from the Paint event! While drawing beyond the boundaries of the PBox you know the new MinSize and set it.. – TaW Nov 28 '16 at 19:37

0 Answers0