跟著滑鼠指標跑


一個Form1
一個PictureBox1
一個陳述式
X, Y坐標寫在 Form1 抬頭
Public Class Form1  
    '滑鼠在Form1上的 x,y  
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove  
        MovePic(e.X, e.Y)  
    End Sub  
    '滑鼠在PictureBox1上的 x,y 會擋到 PictureBox1移動的處理  
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove  
        MovePic(e.X + PictureBox1.Left, e.Y + PictureBox1.Top)  
    End Sub  
    '移動陳述式  
    Sub MovePic(ByVal MoveX As Integer, ByVal MoveY As Integer)  
        Me.Text = "X:" & MoveX & ",Y:" & MoveY  
        PictureBox1.Top = MoveY  
        PictureBox1.Left = MoveX  
    End Sub  
End Class

沒有留言:

張貼留言