Identify who invokes Event Handler

ε祈祈猫儿з 提交于 2019-12-02 04:44:50

The sender object in the event handler signature is the control that raised the event.

Simply cast this object and you have access to all the control's information.

Label label = sender as Label;

You do need to be a little bit careful with this, since you are assuming that only controls of type Label are raising events that have this handler method.

That's what the sender is for:

Point p = ((Label)sender).Location;
// adjust p 
label1.Location = p;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!