Incremento/decremento valore con mouse

di
Anonimizzato26608
il
3 risposte

Incremento/decremento valore con mouse

Ciao a tutti mi presento sono nuova del forum e mi chiamo Rita
Volevo sapere se qualcuno può aiutarmi con il Visual Basic 6.0
in un textbox vorrei far visualizzare un numero che a partire dallo 0 aumenta di valore con il click del tasto sinistro del mouse
mentre lo stesso valore diminuisce con il tasto destro del mouse fino a raggiungere lo 0 (devo azionare un timer)
ho scritto qualcosa che si addice alle mie esigenze però vorrei farlo funzionare togliendo i command1 e command2 e cliccando con i tasti sinistro destro del mouse in un punto qualsiasi del Form
Mi scuso con il moderatore però non sono riuscito a trovare il pulsante code per inviare il codice

Private Sub Command2_Click()
If txtnumero.Text < 99 Then
txtnumero.Text = txtnumero.Text + 1
End If
End Sub

Private Sub Command1_Click()
If txtnumero.Text > 0 Then
txtnumero.Text = txtnumero.Text - 1
End If

End Sub

Grazie mille

3 Risposte

  • Re: Incremento/decremento valore con mouse

    Perhaps use the GetAsyncKeyState() API within the the MouseDown event:

    The Code:

    Option Explicit

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Const VK_LBUTTON = &H1
    Private Const VK_RBUTTON = &H2

    Private Sub Form1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim tTimer As Single

    If Button = vbLeftButton Then

    ' Loop while the Left Mouse is depressed.
    Do While GetAsyncKeyState(VK_LBUTTON) <> 0

    ' Perform your "While Mouse is Down" code in
    ' this "While" loop.

    If (Timer - tTimer) > 0.05 Then
    ' Increment a Textbox value (using a delay to slow the increment)
    Text1.Text = Val(Text1.Text) + 1
    tTimer = Timer
    End If

    DoEvents
    Loop

    End If


    If Button = vbRightButton Then

    ' Loop while the Right Mouse is depressed.
    Do While GetAsyncKeyState(VK_RBUTTON) <> 0

    ' Perform your "While Mouse is Down" code in
    ' this "While" loop.

    If (Timer - tTimer) > 0.05 Then
    ' Decrement a Textbox value (using a delay to slow the decrement)
    Text1.Text = Val(Text1.Text) - 1
    tTimer = Timer
    End If

    DoEvents
    Loop

    End If

    End Sub
  • Re: Incremento/decremento valore con mouse

    Buon_uomo... questo è un forum italiano e la richiesta è di luglio...
  • Re: Incremento/decremento valore con mouse

    Grazie mille della risposta Buon_uomo
Devi accedere o registrarti per scrivere nel forum
3 risposte