请问,怎样通过滚动条调整picturebox中的图片的大小谢谢了

解决方案 »

  1.   

    Option ExplicitPrivate Sub Form_Load()
        HScroll1.Value = 1
        HScroll1.LargeChange = 1
        
        HScroll1.Max = 10
        
    End SubPrivate Sub HScroll1_Change()
        Picture1.Move 3, 3, Picture1.Height * HScroll1.Value, Picture1.Width * HScroll1.Value
        
    End Sub
      

  2.   

    Private 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 Long'在Form上放一个picture box,并事先定义好一个图片,增加一个按钮
    '例2: 放大或缩小图片
    '放大:
    Private Sub Command1_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Picture1.hdc, 0, 0, w * 2, h * 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
    '缩小:
    Private Sub Command2_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Me.hdc, 0, 0, w / 2, h / 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
    '例3: 翻转图片
    '左右翻转
    Private Sub Command3_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Me.hdc, w, 0, -w, h, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
    '上下翻转
    Private Sub Command4_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Me.hdc, 0, 0, w / 2, h / 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
    '左右并且上下翻转
    Private Sub Command5_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Me.hdc, w, h, -w, -h, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub