Wednesday, April 4, 2012

.NET Event Handlers

Example is the FormClosedEventHandler:
When you create a FormClosedEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event.

The associated event has the following signature: public event FormClosedEventHandler FormClosed

This is the signature of the FormClosedEventHandler:

public delegate void FormClosedEventHandler(
Object sender,
FormClosedEventArgs e
)


http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosedeventhandler.aspx

example from a Form1.Designer.cs:
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed)
;

Depending on the precise data the event passes to handlers, you may be able to use an existing event data class in the .NET Framework. For example, if your event handler allows the action associated with the event to be cancelled, you can use the CancelEventArgs class.


http://msdn.microsoft.com/en-us/library/wkzf914z.aspx

On events vs delegates:

[Events] are a modifier [sic] on the delegate type, which adds some restrictions that the compiler enforces and also adds two accessors (similar to the get and set for properties).


http://blog.monstuff.com/archives/000040.html

No comments:

Post a Comment