Is there a way to raise button's click event by code.
For examples, button 1's click event maybe used by many place, Another button 2, if user click, is there a way to raise button 1's click event.
button1.Click += ......
....
void Button2_Click(Object send, , EventArgs e)
{
How to raise button 1 event
Don't know button1.Click event handler is used by other code
Want boradcast event to all listeners
}

How to raise a ready control's event
Robert Liu
-vj
Don Jelley
Reflection probably would be the answer but I have not been able to make it work.
rem mi is one of a variety of toolstripmenuitems
Dim typ As Type = mi.GetType
Dim ev As System.Reflection.EventInfo = typ.GetEvent("Click")
If ev Is Nothing Then Throw LI.ErrHandler.Goof("Program error: could not find a click event for menu item~n{0}~nwhose text is~n{1}.", mi.Name, mi.Text.Replace("&", ""))
Dim rm As System.Reflection.MethodInfo = ev.GetRaiseMethod()
If rm Is Nothing Then Throw LI.ErrHandler.Goof("Program error: could not find a click raise method for menu item~n{0}~nwhose text is~n{1}.", mi.Name, mi.Text.Replace("&", ""))
Dim ea As New EventArgs
Dim params() As Object
ReDim params(1)
params(0) = mi
params(1) = ea
rm.Invoke(mi, params)One or the othr of the Goof's always get's thrown, I forget which at the moment. In this example MI is clickable and now that I've found performclick that's which I'll use.
QUESTION: I assume that performclick is a synchronous activity (control doesn't return to the calling routine until after the click processing is completed.) CORRECT
Regards,
Al
kcvaio
You can still directly call the method that is hooked up to the click event, if you wish to perform the work.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("Clicked")
End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadButton1_Click(Button1, EventArgs.Empty)
End SubLarryNeedsHelp
Roland51
Opps, I've just realized I'm in the wrong forum - my question relates to Visual Basic, not C#. I don't seem to be able to delete the post though so maybe somebody here will have a suggestion.