简体   繁体   English

对象发件人控制发件人?

[英]Object sender to control sender?

Is there a way for me to change object sender into, say, control sender? 我有办法将对象发送方更改为控制发送方吗? What I want in the end is for object sender to tell me the controller count (controller 15, for instance), rather then it tell me "system.project.label, text : 'text here'". 最后,我想要的是对象发送方告诉我控制器的数量(例如,控制器15),而不是告诉我“ system.project.label,text:'text here'”。

I do have a way around this issue by looking through each controller on a sheet and matching object sender to said controller, but that is a fairly lengthy workaround. 通过浏览工作表上的每个控制器并将对象发送方匹配到所述控制器,我确实有解决此问题的方法,但这是一个相当长的解决方法。 I'm curious if anyone knows a way to get sender to report it's control location instead. 我很好奇是否有人知道让发送者报告其控制位置的方法。

Assuming you are talking about the object sender argument of an event handler, then you can always cast it to a control. 假设您正在谈论事件处理程序的object sender参数,那么您始终可以将其强制转换为控件。

if(sender is Control)
{
   var myControl = sender as Control;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM