在一个按钮的事件处理程序中,单击我然后再重新使用另一个事件处理程序/点击。然而,我似乎无法弄清楚如何做到这一点。
可能引起麻烦的一点是,我要点燃的第二个项目的处理程序不是在同一个表单/上下文。
似乎我应该可以调用方法...
但我似乎无法做到这一点。
这是在紧凑框架/ Win Mobile
解决方案您需要执行以下操作之一:
- 提供访问权限处理程序包含类实例(即对该对象的引用)
- 使处理程序成为静态,所以任何实例都可以直接引用它。
- 将处理程序在一些其他全球可用的对象(静态,单例等)中,所以两个消费者都可以使用它
- 使用提供事件聚合的框架,所以你不必担心这样的事情。 li>
I must be missing something obvious - I am new to .NET - been developing in C++/MFC for years.
In an event handler for a button click I would like to then re-use another event handler/click. However, I can't seem to figure out how to do that.
The bit that may be causing trouble is that the handler for the second item I want to "fire" is not on the same form/context.
It seems that I should just be able to call the method...
But I don't seem to be able to do it.
This is in compact framework/Win Mobile
解决方案You need to do one of the following:
- Provide access to the handler's containing class instance (i.e. a reference to that object)
- Make the handler a static so any instance can reference it directly
- Put the handler in some other globally available object (static, singleton, etc) so both consumers can use it
- Use a framework that provides event aggregation so you don't have to worry about such things
更多推荐
如何调用/调用按钮单击事件处理程序形成另一个处理程序? (C# )
发布评论