基于调用它的对象实例执行事件处理程序例程的各个部分 [英] executing sections of an event handler routine based on the object instance that called it

查看:61
本文介绍了基于调用它的对象实例执行事件处理程序例程的各个部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以基于引发事件处理程序的对象实例来调用事件处理程序的代码部分?

我有三个下拉列表,它们是使用反射动态创建的.这样,对所有三个下拉列表进行了编码,都引发了一个相同的SelectedIndexChanged事件处理程序.

在事件处理程序的主体中,我希望根据调用它的对象来执行代码的各个部分.例如.从下拉列表A中选择一个值将执行代码部分以填充下拉列表B.从下拉列表B中选择一个值将执行代码部分以填充下拉列表C.

我假设由于我可以创建一系列下拉列表使用反射技术,我还可以创建一个事件处理程序,该事件处理程序将满足多个下拉列表的需求?我看到的另一种选择是为每个人创建一个单独的处理程序,这肯定会否定首先采用反射的目标.

如果有人可以将我指向正确的方向,我将非常感激.

Is there a way to invoke code sections of an event handler based upon the object instance that has raised it?

I have three dropdownlists which are dynamically created using reflection. As such all three dropdownlists are coded raise the same SelectedIndexChanged event handler.

In the body of the event handler I wish to execute sections of the code depending upon which object called it. Eg. selecting a value from dropdownlist A would execute the code section to populate dropdownlist B. Selecting a value from dropdownlist B would execute the code section to populate dropdownlist C.

I would assume that since i can create a series of dropdownlists using the reflection technique that i can also create an event handler that will service the requirements of more than one dropdownlist? The alternative as i see it would be to create a seperate handler for each one which would surely negate the objective of adopting reflection in the first place.

I would very much apprieciate if someone could point me in the right direction.

推荐答案

事件处理程序方法的第一个参数(通常称为sender)是对引发事件的控件的引用.您可以检查它所引用的控件并采取相应的措施.

The first parameter to the event handler method (usually called sender) is a reference to the control that raised the event. You can check which control it refers to and act accordingly.


这篇关于基于调用它的对象实例执行事件处理程序例程的各个部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆