在Form中添一个PictureBox,在Picture1里添一个image,image的stretch设为true
Public Sub ScaleShowPic(Frm As Form, pic1 As PictureBox, Image1 As Image)
Dim scalew As Single, scaleh As Single, k As Single
Dim w As Long, h As Long
Dim oldw As Long, oldh As Long
If scalew > 1 Or scaleh > 1 Then
If scalew <= scaleh Then
h = pic1.Height
w = k * h
Image1.Height = h
Image1.Width = w
Image1.Stretch = True
Else
w = pic1.Width
h = pic1.Width / k
Image1.Height = h
Image1.Width = w
Image1.Stretch = True
End If
Image1.Left = (pic1.Width - w) / 2
Image1.Top = (pic1.Height - h) / 2
Else
w = Image1.Width
h = Image1.Height
Image1.Stretch = True
Image1.Left = (pic1.Width - Image1.Width) / 2
Image1.Top = (pic1.Height - Image1.Height) / 2
End If
Image1.Visible = True
End Sub