本人刚学vb,还有很多地方不懂,特来请教大虾们
问题是这样:我有一个form1的窗体,里面有一个image控件,我是想使在form2中显示image中的图片,并使其根据图片的大小自动更改窗体的大小。
我写的部分代码如下:
form2.Picture = form1.Image1.Picture
form2.Height = Image1.Picture.Height
form2.Width = Image1.Picture.Width
我尝试过使用ScaleHeight也不能准确调整窗体,相信是图片单位的处理没有做好。还有想问一下,Image1.Picture的单位是twip,还是像素?我已把窗体的scaleMode设置成像素。
问题是这样:我有一个form1的窗体,里面有一个image控件,我是想使在form2中显示image中的图片,并使其根据图片的大小自动更改窗体的大小。
我写的部分代码如下:
form2.Picture = form1.Image1.Picture
form2.Height = Image1.Picture.Height
form2.Width = Image1.Picture.Width
我尝试过使用ScaleHeight也不能准确调整窗体,相信是图片单位的处理没有做好。还有想问一下,Image1.Picture的单位是twip,还是像素?我已把窗体的scaleMode设置成像素。
Private Sub Command2_Click()
With Form2
.Image1.Picture = Form1.Image1.Picture
.Image1.Stretch = True
.Width = .Image1.Width + 120
.Height = .Image1.Height + 500
.Show
End With
End Sub
窗体大小应该加上4边宽度。
form2.Height = Image1.Picture.Height + (form2.height - form2.scaleheight)
form2.Width = Image1.Picture.Width + (from2.width - form2.scalewidth)
1楼的方法可以,但是觉得不是很精确。width+130效果可能会好点。但是+120和+500这两个数字如何确定?有没有其他简单点的方法?
这样无论窗体式样和桌面主题如何变化,都是正确的。
form2.Picture = Form1.Image1.Picture
form2.Height = Form1.Image1.Picture.Height + (form2.Height - form2.ScaleHeight)
form2.Width = Form1.Image1.Picture.Width + (form2.Width - form2.ScaleWidth)
form2.Show
这样调试的效果还是一样,多出很多空白,是否我其他设置有错?
不管怎样,我都很感激你的积极回答!谢谢!
Form2.Picture = Form1.Image1.Picture
那么当
form2.Height = Form1.Image1.Picture.Height
所谓form2.Height与图片本身的Height相等。