Centered and scrolled PictureBox in WinForms?

For the PictureBox set SizeMode = AutoSize Anchor it Top, Left and set its Location to 0, 0.

For the PictureBox, set SizeMode = AutoSize, Anchor it Top, Left, and set its Location to 0, 0. Set Panel. AutSize to False and Panel.

AutoScroll to True. When you set the PictureBox. Image property, it will auto-size to the size of the image.

You can then use that size to set the panel's AutoScrollPosition property: public Image CapturedImage { set { pictureBoxCapturedImage. Image = value; panelCapturedImage. AutoScrollPosition = new Point { X = (pictureBoxCapturedImage.

Width - panelCapturedImage. Width) / 2, Y = (pictureBoxCapturedImage. Height - panelCapturedImage.

Height) / 2 }; } } If the image is smaller then then panel's size, it will remain in the upper left corner. If you want it centered within the panel, you'll have to add logic to set its Location appropriately.

Thanks, I though there was an automatic way to do that. I'll take your approach! – brafales Oct 17 at 20:22 You know that all of this can be done auto by setting the properties of the control.. – gbianchi Oct 17 at 23:17 Will try that, thanks – brafales Oct 18 at 7:09.

The picturebox has to be set to autosize. Anchored at the center (or a border). You could manage all of this in the designer, don't undertand your problem with that.

The panel has to be set to autoscroll to true.

I don't know how to add the PictureBox as a child control of the Panel in the designer, when I drop it onto the panel it's added into the form, not inside the Panel – brafales Oct 17 at 19:38 Ok yes it seems the control is added inside the panel, however, if I set the picturebox to autosize, the image is not centered inside the panel. How do I achieve this? I can't see the option to anchor it to the center – brafales Oct 17 at 19:45 If you not anchor it to anything, it will be centered by default.

– gbianchi Oct 17 at 23:16.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions