Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

[VisualBasic]請問如何用滑鼠事件寫下列程式

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    Option Explicit

    '請加入一個Label及一個Timer並把程式碼複製到Form裡

    'Program By CHTEL WORKSHOP http://chtel.myweb.hinet.net

    Dim ShotEnabled As Boolean

    Private Sub Form_Load()

    ShotEnabled = True

    Timer1.Enabled = False

    End Sub

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If ShotEnabled And Button = 1 Then

    Timer1.Interval = 20

    Timer1.Enabled = True

    ShotEnabled = False

    End If

    End Sub

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If ShotEnabled Then

    Label1.Move X + 25, Y + 25

    End If

    End Sub

    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If ShotEnabled Then

    Label1.Move Label1.Left + X + 25, Label1.Top + Y + 25

    End If

    End Sub

    Private Sub Timer1_Timer() '為了降低CPU使用率所以使用Timer而不使用DoEvents

    If Label1.Left > Me.Width Then

    Timer1.Enabled = False

    ShotEnabled = True

    End If

    Label1.Left = Label1.Left + 200

    End Sub

Still have questions? Get your answers by asking now.