Button events

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
I am trying to keep my code 'tidy' by incorporating the MouseDown and MouseUp events for the same button into one event.

VB.NET:
Private Sub Button4_Event (byval sender as object, byval e as system.Windows.Forms.MouseEventArgs) handles Button4.MouseDown, Button4.MouseUp
    'if e = MouseDown then
    'else
    'end if
End Sub

The problem is, I cant seem to find a way of detecting which event (ie the MouseDown or the MouseUp) fired the Sub. Is this actually possible, or will I have to split it over two Subs?
 
Not possible. Multiple handles is normally used to handle same event for multiple objects.
 
VB.NET:
Declare Function GetKeyState Lib "user32.dll" (ByVal vk As Integer) As Integer
	Private Sub Button1_Event(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown, Button1.MouseUp
		If e.Button = Windows.Forms.MouseButtons.Left Then
			If GetKeyState(1) >= &H1000 Then
				TextBox1.Text = "Left button down"
			Else
				TextBox1.Text = "Left button up"
			End If
		Else
			If GetKeyState(2) > =&H1000 Then
				TextBox1.Text = "Right button down"
			Else
				TextBox1.Text = "Right button up"
			End If
		End If
	End Sub
 
Last edited by a moderator:
ok, so it's possible ;) but there don't exist a reason to do it.
 
If you kept all your physical belongings in one box, it may look 'tidy' from the outside but what a mess it would be on the inside. Or, even if you kept it 'tidy' somehow on the inside, it would require more work.
A place for everything and everything in it's place.
 
Back
Top