How to attach EventArgs/custom params when you assign a delegate to the event?

c#

Solution

You cannot "assign additional data" to a delegate, but you can create a parameterized version of the `form_Resize` method and then use lambda expressions (in C# 3+) or anonymous delegates (C# 2+) to specify the additional data when attaching the handler. One way to write this is following:

void form_Resize(object sender, EventArgs e, Data additional) {
  // 'additional' contains whatever you specified when attaching handler
}

this.form.Resize += (s, e) => form_Resize(s, e, yourAdditionalData);

Problem

I have this code: ``` this.form.Resize += new EventHandler(form_Resize); ``` But I want to assign some objects for later access in the `form_Resize` event, how can I do that? and do I access the data in the EventArgs?

Original source