E
eBob.com
I need a mouse button which does its thing when clicked, and keeps repeating
its thing when held down. I know that the code below is not very
sophisticated but I think that it is adequate for my immediate needs. The
problem is that when I depress and hold the mouse button down the button
does absolutely nothing. When clicked once it does what it should, i.e.
deletes the leftmost character. When clicked one and a half times, i.e.
clicked once and then immediately depressed and held, it goes into
repeat-a-matic mode. But I can't see why it is doing nothing when I depress
and hold it.
The code is dirt simple. I'd be very Thanksgiving if you'd look at it and
see if you can tell me what I am doing wrong.
Thanks, Bob
(btnLeftDel and TextBox1 are placed on a form using the designer.)
Option Strict On
Option Explicit On
Imports System.Threading
Public Class Form1
Dim LeftButtonDown As Boolean = False
Private Sub btnLeftDel_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnLeftDel.MouseDown
'remove leftmost character
Dim counter As Integer = 0
LeftButtonDown = True
Do While (TextBox1.Text.Length > 0) And _
(LeftButtonDown)
If counter = 0 Then
TextBox1.Text = TextBox1.Text.Substring(1)
'Application.DoEvents() 'doesn't help
End If
'counter += 1
Thread.Sleep(200)
Application.DoEvents() 'without this a single click always deletes 2
characters
'If counter = Form1.MouseBtnDownRepeatFactor Then counter = 0
Loop
End Sub
Private Sub btnLeftDel_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnLeftDel.MouseUp
LeftButtonDown = False
End Sub
End Class
its thing when held down. I know that the code below is not very
sophisticated but I think that it is adequate for my immediate needs. The
problem is that when I depress and hold the mouse button down the button
does absolutely nothing. When clicked once it does what it should, i.e.
deletes the leftmost character. When clicked one and a half times, i.e.
clicked once and then immediately depressed and held, it goes into
repeat-a-matic mode. But I can't see why it is doing nothing when I depress
and hold it.
The code is dirt simple. I'd be very Thanksgiving if you'd look at it and
see if you can tell me what I am doing wrong.
Thanks, Bob
(btnLeftDel and TextBox1 are placed on a form using the designer.)
Option Strict On
Option Explicit On
Imports System.Threading
Public Class Form1
Dim LeftButtonDown As Boolean = False
Private Sub btnLeftDel_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnLeftDel.MouseDown
'remove leftmost character
Dim counter As Integer = 0
LeftButtonDown = True
Do While (TextBox1.Text.Length > 0) And _
(LeftButtonDown)
If counter = 0 Then
TextBox1.Text = TextBox1.Text.Substring(1)
'Application.DoEvents() 'doesn't help
End If
'counter += 1
Thread.Sleep(200)
Application.DoEvents() 'without this a single click always deletes 2
characters
'If counter = Form1.MouseBtnDownRepeatFactor Then counter = 0
Loop
End Sub
Private Sub btnLeftDel_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnLeftDel.MouseUp
LeftButtonDown = False
End Sub
End Class