A Programmer's Dream

Still More Interfaces...

Posted by Stephen Wrighton on 10 May 2007

I know, I'm on an interfaces kick. Well, that's what I've been working on/with all week, so it's perfectly understandable.

Anyways, I'm building that interface system so that I can treat all my custom server controls for the project in the exact same way. Well, I came across the realization that I needed to be able to raise events. Basically, there's a specific framework in the application for displaying messages to the user in the same way for every message. Well, to get information from the depths of some of these controls, they were raising events.

And since I'm treating every control in the exact same manner, I can't make allowances that some controls will implement the event and not others. Therefore, the interface must declare the event.

Which ended up being surprisingly simple.

First I built the EventArgs class whose information is being passed back and forth for. Then after that I defined the delegate:
public delegate void DisplayMessageEventHandler(object sender, DisplayMessageEventArgs e);
Then after I had my delegate defined, I added in the event code into the interface :
event DisplayMessageEventHandler DisplayMessage;
Like I said, it was surprisingly simple.

Tweet me @kidananubix if you like this post.