0

I have a picturebox and i can zoom it.

When i zoom the picturebox i need to scroll left or right the image.

Can you tell me why when i zoom the image the left side is fixed and i can't scroll on left?

I have activated the AutoScroll on the main panel, but i can scroll only to right, but my image is centered and i need to scoll also to left.

What i want is like when you zoom and scroll an image inside a Photo app in Win 10. But i'm using the scoll bar and not the mouse pointer.

The structure is like in the next image, in red the main panel, and i green the picturebox.

enter image description here

    private void image_Scroll(object sender, EventArgs e)
    {
        int pbWidth = pbImg.Image.Width + (pbImg.Image.Width * ztb.Value / 100);
        int pbHeight = pbImg.Image.Height + (pbImg.Image.Height * ztb.Value / 100);

        int mpWidth =  mainPanel.Width:
        int mpHeight = mainPanel.Height;

        int pbX = (mpWidth - pbWidth) / 2;
        int pbY = (mpHeight - pbHeight) / 2;

        pbImg.Size = new Size(pbWidth, pbHeight);

        Point p = new Point(pbX, pbY);
        pictureBox.Location = p;
    }
  • a) do not center the image but set pbox to zoom. b) __nest__ it in an autoscroll panel. c) to zoom in and out change pbox.size. Done. – TaW May 31 '19 at 08:02
  • the Size Mode of the picturebox is set to Zoom, and the AutoScroll of the main panel is set on True.With the Zoom scrollbar i can zoom in or zoom out, but when the image is over the left and right borders of the main panel, the main panel shows the the scrollbar, but the scrollbar starts from left, so i can't move on the left side of the big image –  May 31 '19 at 08:16
  • Do not put any other control into the autoscroll panel or else they will scroll away! - If you want to keep the pbox centered in the panel you will have to write code for that. Show us the zooming code! - Other than that, an autoscroll panel __will__ allow you to scroll any nested control into view. – TaW May 31 '19 at 08:20
  • should I insert a panel beetwen the main panel and the picturebox? –  May 31 '19 at 09:45
  • Yes, I would do that. – TaW May 31 '19 at 09:46
  • if i insert the second panel, when i place the picturebox after the zoom, have i to place the second panel and not the picturebox ? I added the zoom code in the main post –  May 31 '19 at 09:50
  • I would place the autoScrollPanel below the groupbox and maybe anchor it on all sides. Then move the pbox inside it with the mouse and keep zooing be changing the pbox size and maybe location. The zoom code looks ok to me.. – TaW May 31 '19 at 09:54

0 Answers0