3
votes

It is possible to set SizeMode Zoom and apply padding?

The following will work:

    ibPic2DLeft.SizeMode = PictureBoxSizeMode.Normal;
    ibPic2DLeft.Padding = new Padding(100, 100, 50, 50);

The following will not work:

        ibPic2DLeft.SizeMode = PictureBoxSizeMode.Zoom;
        ibPic2DLeft.Padding = new Padding(100, 100, 50, 50);

What are the alternatives of padding that are compatible with zoom?

2
do you want some space on all the side of image? I am bit unclear with your question - jparthj
I do like to apply some sort of padding. A this point it is not important what kind of padding i want to apply. The problem is that i can not apply any kind of padding when the sizemode is set to zoom - Ben
then better you create a thumbnail with size less than the size of your picturebox and then set it to the normal mode. For obvious reasons, you can not set padding in zoom mode. The image will cover optimum part of the picture box. - jparthj
You are totally right with that one. However is there any function similar to padding that is compatible with the zoom mode? - Ben
unfortunately no, there is not any other function to do so! BTW is the size of the image is fixed for all the images shown by the picturebox? or it is dynamic? - jparthj

2 Answers

2
votes

Put the PictureBox inside a Panel. Set the PictureBox to Dock=Fill. Set PictureBox SizeMode=Zoom. Apply Padding to the Panel.

0
votes

you can better go for this approach, when your image size is less than the size of the picture box, you can use normal mode and when your picture size is bigger than picture box you can use zoom mode. This is the best dynamic approach i found for my application solution in past.

Image oImg = yourImage;

if ((oImg.Height > ibPic2DLeft.Height | oImg.Width > ibPic2DLeft.Width)) {
    ibPic2DLeft.SizeMode = PictureBoxSizeMode.Normal;
} else {
    ibPic2DLeft.SizeMode = PictureBoxSizeMode.Zoom;
}