Thursday, July 01, 2010

Event Firing Delegate Handlers For Basic Use Controls

Sometimes it's nice and tidy and simply easy to create a small user control which can listen fire events when it does something. This requires the use of delegates, the format of which escapes me every single time. Argh!

Anyway, here's an example:
public delegate void ChartSelected(int chartId);
public ChartSelected onChartSelected = null;
So the parent control or page would assign a method to the onChartSelected delegate to be fired when, in this case, a chart is selected:
selector.onChartSelected = MyEventMethod;
And the method fired when called would look like the delegate identifier:
private void ChartSelected(int chartId)
// do something
Of course, the control declaring the delegate has to fire the event at some point:
if (onChartSelected != null)

No comments:

Post a Comment