滑鼠左鍵按住不放-->移動圖片,中鍵滾輪前後-->縮放圖片


PictureBox1 and Panel1 的功能程式

    Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
        PictureBox1.Select()
    End Sub
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        Me.Cursor = Cursors.Hand
        If e.Button = Windows.Forms.MouseButtons.Left Then
            With PictureBox1
                tmpY = e.Y
                tmpX = e.X
            End With
        End If
    End Sub
    Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        PictureBox1.Select()
        If e.Button = Windows.Forms.MouseButtons.Left Then
            With PictureBox1
                .Top += e.Y - tmpY
                .Left += e.X - tmpX
            End With
        End If
    End Sub
    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        Me.Cursor = Cursors.Default
    End Sub
    Private Sub PictureBox1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseWheel
        On Error Resume Next
        With PictureBox1
            If e.Delta <= 0 Then
                If .Width < 10 Then Exit Sub
            End If
            .Width += CInt(.Width * e.Delta / 1000)
            .Height += CInt(.Height * e.Delta / 1000)
        End With
    End Sub

沒有留言:

張貼留言