Thursday, May 10, 2007

Still More Interfaces...

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.

No comments:

Blog Widget by LinkWithin