Visual Basic.net 2003 - Mouse status

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I hope I have found the right group to post this question to, if not please
point me in the right direction.

I have VB.net 2003 and need to make a button that performs an action only
when pressed and the action STOP when the button is released.

I have tried putting the following into the program:

Private Sub btnFocusPlus_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnFocusPlus.MouseDown
'Check if port open
Dim x As Integer
If Not ComPortOpen = 1 Then
Beep()
WriteMessage("No Port Open")
Exit Sub
End If

For x = 1 To 5

If not btnFocusPlus.MouseButtons.Left Then
Exit Sub
Else
'Lengthen the Focus 10 point
LV = 50
m_CommPort.Write("Mf-" + LV & Chr(13))
End If
Next
End Sub

This basically sends a command "Mf-50" to the COM port for a loop of 5 times
each time the button is pressed down. I want to break the loop if the button
is released.

I just can't seem to find something like Button Up.

Any ideas or help greatly acknowledged.
--
Cheers
Chas

***************
* Spectrum is Green *
***************
 
Private Sub btnFocusPlus_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnFocusPlus.MouseDown
' your COM port code goes here
End Sub

Private Sub btnFocusPlus_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnFocusPlus.MouseUp
' stop code goes here
End Sub
 
Dear Milosz

They say the simplest answers are the best. This worked. I put a do loop in
the Mouse Down to check for a variable value in the Mouse Up. Perfect.

Thank you very much.
--
Cheers
Chas

***************
* Spectrum is Green *
***************
 
Back
Top