views:

25

answers:

2

Hello! i have a standard mouseEventHandler :

a.MouseClick += new MouseEventHandler(labelClick);

where a is a label. the function called on click is like so :

private void labelClick(object sender,MouseEventArgs mea)
        {
            MessageBox.Show("click on the label");
        }   

How can i send more information to the called function? (i.e. i have a lot of labels ; for each label i would like to send 2 strings for my location and address )

Regards, Alexandru Badescu

+3  A: 

Maybe you can use the Tag property of the label and cast the sender parameter as a label and read the Tag property.

Set the Tag property to the

string.Format("{0};{1}", Location, Address)

Then in the event handler

Label lbl = sender as Label;
String[] LocAdd = ((String)lbl.Tag).Split(';');

Now you have the Location in the first item in the array and the Address in the second one.

A_Nablsi
+2  A: 
a.MouseClick += (sender, e) => HandleLabelMouseClick(sender, e, "whatever1", "whatever2");

private void HandleLabelMouseClick(object sender, MouseEventArgs e, string whatever1, string whatever2)
{
    MessageBox.Show(whatever1 + "\n" + whatever2);
}
max