try itOption ExplicitPrivate Sub Form_Load() Picture1.AutoSize = True End SubPrivate Sub Form_Resize() Picture1.Move Form1.Left, Form1.Top, Form1.Width, Form1.Height End Sub
借用别人给我的代码: Option ExplicitPrivate Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As LongDim intPicturePos As IntegerPrivate Sub PaintPicInCenter() With picTmp .Cls Set .Picture = Nothing .Height = Me.ScaleHeight / Screen.TwipsPerPixelY .Width = Me.ScaleWidth / Screen.TwipsPerPixelX BitBlt .hDC, (.ScaleWidth - picBack.ScaleWidth) / 2, (.ScaleHeight - picBack.ScaleHeight) / 2, picBack.ScaleWidth, picBack.ScaleHeight, picBack.hDC, 0, 0, vbSrcCopy .Refresh Set .Picture = .Image Set Me.Picture = Nothing Set Me.Picture = .Picture Me.Visible = False Me.Visible = True End With End SubPrivate Sub PaintPicFullSize() With picTmp .Cls Set .Picture = Nothing .Height = Me.ScaleHeight / Screen.TwipsPerPixelY .Width = Me.ScaleWidth / Screen.TwipsPerPixelX
StretchBlt .hDC, 0, 0, .ScaleWidth, .ScaleHeight, picBack.hDC, 0, 0, picBack.ScaleWidth, picBack.ScaleHeight, vbSrcCopy .Refresh Set .Picture = .Image Set Me.Picture = Nothing Set Me.Picture = .Picture Me.Visible = False Me.Visible = True End With End SubPrivate Sub MDIForm_Load() Form1.Width = 4000 Form1.Height = 3000 Form1.Show End SubPublic Property Let PicturePos(ByVal intPos As Integer) If intPicturePos <> intPos Then intPicturePos = intPos Call MDIForm_Resize End If End PropertyPublic Property Get PicturePos() As Integer PicturePos = intPicturePos End PropertyPrivate Sub MDIForm_Resize() If Me.WindowState = 1 Then Exit Sub If intPicturePos = 0 Then Call PaintPicInCenter Else Call PaintPicFullSize End If End Sub 再设置MDIForm1.PicturePos = 0 MDIForm1.PicturePos = 1我试过,搞定
Picture1.AutoSize = True
End SubPrivate Sub Form_Resize()
Picture1.Move Form1.Left, Form1.Top, Form1.Width, Form1.Height
End Sub
Option ExplicitPrivate Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As LongDim intPicturePos As IntegerPrivate Sub PaintPicInCenter()
With picTmp
.Cls
Set .Picture = Nothing
.Height = Me.ScaleHeight / Screen.TwipsPerPixelY
.Width = Me.ScaleWidth / Screen.TwipsPerPixelX
BitBlt .hDC, (.ScaleWidth - picBack.ScaleWidth) / 2, (.ScaleHeight - picBack.ScaleHeight) / 2, picBack.ScaleWidth, picBack.ScaleHeight, picBack.hDC, 0, 0, vbSrcCopy
.Refresh
Set .Picture = .Image
Set Me.Picture = Nothing
Set Me.Picture = .Picture
Me.Visible = False
Me.Visible = True
End With
End SubPrivate Sub PaintPicFullSize()
With picTmp
.Cls
Set .Picture = Nothing
.Height = Me.ScaleHeight / Screen.TwipsPerPixelY
.Width = Me.ScaleWidth / Screen.TwipsPerPixelX
StretchBlt .hDC, 0, 0, .ScaleWidth, .ScaleHeight, picBack.hDC, 0, 0, picBack.ScaleWidth, picBack.ScaleHeight, vbSrcCopy
.Refresh
Set .Picture = .Image
Set Me.Picture = Nothing
Set Me.Picture = .Picture
Me.Visible = False
Me.Visible = True
End With
End SubPrivate Sub MDIForm_Load()
Form1.Width = 4000
Form1.Height = 3000
Form1.Show
End SubPublic Property Let PicturePos(ByVal intPos As Integer)
If intPicturePos <> intPos Then
intPicturePos = intPos
Call MDIForm_Resize
End If
End PropertyPublic Property Get PicturePos() As Integer
PicturePos = intPicturePos
End PropertyPrivate Sub MDIForm_Resize()
If Me.WindowState = 1 Then Exit Sub
If intPicturePos = 0 Then
Call PaintPicInCenter
Else
Call PaintPicFullSize
End If
End Sub
再设置MDIForm1.PicturePos = 0
MDIForm1.PicturePos = 1我试过,搞定
Image1.Left = 0
Image1.Width = Picture1.Width
Image1.Height = Picture1.Height
Image1.Stretch = True
Private Sub Form_Resize()
Picture1.Top = 0
Picture1.Left = 0
Picture1.Width = Me.Width
Picture1.Height = Me.Height
End SubPrivate Sub Picture1_Resize()
Image1.Top = 0
Image1.Left = 0
Image1.Width = Picture1.Width
Image1.Height = Picture1.Height
Image1.Stretch = True
End Sub
学习了
补充:
(这样运行没有错误)
Private Sub MDIForm_Resize() Picture1.Top = 0
' Picture1.Left = 0
' Picture1.Width = Me.Width
Picture1.Height = Me.Height
End SubPrivate Sub Picture1_Resize()
Image1.Top = 0
Image1.Left = 0
Image1.Width = Picture1.Width
Image1.Height = Picture1.Height
Image1.Stretch = True
End Sub