i have a standard mouseEventHandler :
a.MouseClick += new Mous开发者_开发百科eEventHandler(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
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.MouseClick += (sender, e) => HandleLabelMouseClick(sender, e, "whatever1", "whatever2");
private void HandleLabelMouseClick(object sender, MouseEventArgs e, string whatever1, string whatever2)
{
MessageBox.Show(whatever1 + "\n" + whatever2);
}
精彩评论