Skip navigation

How to programmatically raise an event in C#

Some say you can’t.

Other repeatedly and annoyingly say “just call the callback manually, and pass (null, null) for the args”.

Other still find the answer is YOU CAN!!

So, for a Button:

button1.PerformClick() ;

The form itself has a whole series of functions…

this.OnClick( ... );
this.OnClientSizeChanged( ... ) ;

// And
this.RaiseMouseEvent( ... ) ; // (pretty much) undocumented. nobody seems to know how to use this one!

There’s also this REALLY COMPLICATED way using Interop and the SendMessage() WinAPI function. You don’t have to go there though.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: