调整图片框的大小以匹配图像大小 [英] Resize PictureBox to match image size

查看:63
本文介绍了调整图片框的大小以匹配图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果图像尺寸小于显示器尺寸,如何调整图片框的大小以便它可以显示完整图像!我写了一个无法调整大小的代码(但仍然发布代码)

How to resize the Picturebox so it can show the full image if the image size is less than monitor size ! I wrote a code which can not resize (but still posting the code)!

点击按钮加载图片前的代码

Code before loading image on a button click

Dim bmp As Bitmap
bmp = New Bitmap(path)
If bmp.Width < picBox.Image.Width Then picBox.Width = bmp.Width : If bmp.Height < picBox.Image.Height Then picBox.Height = bmp.Height
picBox.Invalidate() : picBox.Refresh()
'picBox.SetBounds(x,y,width,height)

代码不会调整图片框的大小,它只是未受影响!

The code does not resize the picturebox, it's just untouched !

表单只有 picBox 和 groupbox [dock enabled] 控件.

The form has the picBox and a groupbox [dock enabled] control only.

bmp = New Bitmap(dlgOpen.FileName)
picBox.SizeMode = PictureBoxSizeMode.Normal
Dim w As Integer = picBox.ClientSize.Width
Dim h As Integer = picBox.ClientSize.Height
If bmp.Width > w Then
            w = bmp.Width
End If
If bmp.Height > h Then
            h = bmp.Height
End If
If w > Me.Width - grpBox.Width Then
            w = Me.Width - grpBox.Width
End If
If h > grpBox.Height Then
            h = grpBox.Height
End If
picBox.ClientSize = New Size(w, h)
picBox.ImageLocation = dlgOpen.FileName

此代码也不会重新调整图片框的大小.

推荐答案

图片框只能在加载图片前调整大小,加载后是只读的,没有效果!

Picture-box can be re-sized only before loading the image, there after it is read only and has no effect !

这篇关于调整图片框的大小以匹配图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆