Disabling events

  • Thread starter Thread starter dave mann
  • Start date Start date
D

dave mann

Hi,
Does anyone know if there is there an easy way of programmatically disabling
an event?
I want to enable drag-and-drop on a listbox using the listbox_MouseDown
event but also under certain circumstances allow a listbox_DoubleClick
event.
The Mouse_Down event will supercede the DoubleClick event unless disabled.


Many thanks
Dave
 
place a textbox txtcomp on a form, copy paste the code run the prog and
click inside the textbox, the type the word double in the textbox and double
click it

Private Sub txtComp_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs)
MsgBox("One click")
End Sub

Private Sub txtComp_DoubleClick(ByVal sender As Object, ByVal e As _
System.EventArgs)
MsgBox("Double click")
End Sub

Private hasHandler As Boolean = True

Private Sub txtComp_TextChanged(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles txtComp.TextChanged
If txtComp.Text = "double" Then
RemoveHandler txtComp.MouseDown, AddressOf txtComp_MouseDown
hasHandler = False
Else
If hasHandler = False Then
AddHandler txtComp.MouseDown, AddressOf txtComp_MouseDown
hasHandler = True
End If
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
_ Handles MyBase.Load
AddHandler txtComp.DoubleClick, AddressOf txtComp_DoubleClick
AddHandler txtComp.MouseDown, AddressOf txtComp_MouseDown
End Sub

hth Peter
 
Brilliant...many thanks

Dave


Peter Proost said:
place a textbox txtcomp on a form, copy paste the code run the prog and
click inside the textbox, the type the word double in the textbox and double
click it

Private Sub txtComp_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs)
MsgBox("One click")
End Sub

Private Sub txtComp_DoubleClick(ByVal sender As Object, ByVal e As _
System.EventArgs)
MsgBox("Double click")
End Sub

Private hasHandler As Boolean = True

Private Sub txtComp_TextChanged(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles txtComp.TextChanged
If txtComp.Text = "double" Then
RemoveHandler txtComp.MouseDown, AddressOf txtComp_MouseDown
hasHandler = False
Else
If hasHandler = False Then
AddHandler txtComp.MouseDown, AddressOf txtComp_MouseDown
hasHandler = True
End If
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
_ Handles MyBase.Load
AddHandler txtComp.DoubleClick, AddressOf txtComp_DoubleClick
AddHandler txtComp.MouseDown, AddressOf txtComp_MouseDown
End Sub

hth Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top