如何调用/调用按钮单击事件处理程序形成另一个处理程序? (C# ) [英] How Do I invoke/call a button click event handler form another handler? (c# )

查看:113
本文介绍了如何调用/调用按钮单击事件处理程序形成另一个处理程序? (C# )的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在一个按钮的事件处理程序中,单击我然后再重新使用另一个事件处理程序/点击。然而,我似乎无法弄清楚如何做到这一点。



可能引起麻烦的一点是,我要点燃的第二个项目的处理程序不是在同一个表单/上下文。



似乎我应该可以调用方法...



但我似乎无法做到这一点。



这是在紧凑框架/ 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# )的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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