简体   繁体   English

Picturebox,SizeMode缩放和填充

[英]Picturebox, SizeMode Zoom and padding

It is possible to set SizeMode Zoom and apply padding? 是否可以设置SizeMode缩放并应用填充?

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? 与缩放兼容的填充方法有哪些?

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;
}

Put the PictureBox inside a Panel. 将PictureBox放在面板中。 Set the PictureBox to Dock=Fill. 将PictureBox设置为Dock = Fill。 Set PictureBox SizeMode=Zoom. 设置PictureBox SizeMode =缩放。 Apply Padding to the Panel. 将填充应用于面板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM