Event triggering from code

raju_shrestha

Member
Joined
Nov 23, 2003
Messages
14
How can an event be triggered programmatically? As for example, when a button is clicked with a mouse or keyboard, its click event is triggered. How can the same effect be achieved from the code?

Thanks for the answer.
 
If the event is created by you then you can use the RaiseEvent
statement

[VB]
RaiseEvent EventName(Arguments)
[/VB]

If the event is a system event (a button click) you cannot raise it what you can do if you have code in your event is call that code or call the event handler that handles it example:

Button1_Click(Button1,e)

Hope this helps,
 
The calling the event handler will not give the same effect. As for example, if the button is a toggle button, you cant get the pushed up/down effect on the button.

There should be some way to do it. Hope to get the answer.
 
Try calling Button1.OnMouseDown to push it down and Button1.OnMouseUp to let it go. You can do this by inheriting a standard button and exposing these methods publicly or by using the Reflection namespace to call the protected methods.

If this doesnt work, inherit the Button class and create a pushdown and a pushup sub and in it you would do:
Code:
Public Class MyButton
Inherits Button

Public Sub PushDown()
Dim m as Message
m.Create(Me.Handle, &H201, 0, 0) &H201 is the code for WM_LBUTTONDOWN
MyBase.DefWndProc(m)
End Sub

Public Sub PushUp()
Dim m as Message
m.Create(Me.Handle, &H202, 0, 0) &H202 is the code for WM_LBUTTONUP
MyBase.DefWndProc(m)
End Sub

End Class
This should give you an idea for emulating user interaction
Note the code above is untested, it should work in theory however
 
Back
Top