我用的是vb-mdi-form ,在picture里放一幅图片,我要怎么样才能使小图片能随窗体的大小而改变。求救,谢谢!

解决方案 »

  1.   

    可以先计算缩放比例,然后用stretchblt函数缩放图片
      

  2.   

    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
      

  3.   

    pic.PaintPicture pic.Picture, 0, 0, Me.Width, Me.Height
      

  4.   

    借用别人给我的代码:
    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我试过,搞定
      

  5.   

    用不着这么麻烦吧,在picture里面放一个image,用image显示图片    Image1.Top = 0
        Image1.Left = 0
        Image1.Width = Picture1.Width
        Image1.Height = Picture1.Height
        Image1.Stretch = True
      

  6.   

    不好意思,没有贴完整,是下面这段代码
    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
      

  7.   

    楼上完全正确:
    学习了
    补充:
    (这样运行没有错误)
    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