E-Mail:
Get our new Windows 7 eBook (PDF) for $7 with 70+ Tips. Download Now!

Programatically Creating and Invoking Events in C#

  • No Related Post

As some of you know, I code my ASP.NET code-behinds in two languages: C# for hobbies and projects, and VB.NET for work. I never had to instantiate and invoke events manually in C# before, just in VB.NET. But, because of the new stuff I’m doing in Z-Index 255, I had to come up with an implementation for C#. So while I was used to doing this (Though these lines are wildly out of order here):

public event Close
AddHandler Close, AddressOf MyControl_OnClose
RaiseEvent Close
private sub Viewer1_Close(sender as object, e as EventArgs) handles Viewer1.Close()

But in C#, I had to do:

public event EventHandler Close;
Viewer1.Close += new EventHandler(Viewer1_Close);
Close.Invoke(btnClose, EventArgs.Empty);
private void Viewer1_Close(object sender, EventArgs e) { }

This was neccessary for the ZI255 (MV4) design as I have created a new custom control called an Entry Viewer, which populates dynamically and thus must have its onClose event declared, instantiated, and fired programatically.

So if anyone out there knows how to do this in one of these languages, but not the other, hopefully my great deal of GoogleJuice will lead you here.

What Do You Think?

 
33 queries / 0.182 seconds.