且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何调用/调用按钮单击事件处理程序形成另一个处理程序? (C# )

更新时间:2023-12-06 12:12:04

您需要执行以下操作之一:




  • 提供访问权限处理程序包含类实例(即对该对象的引用)

  • 使处理程序成为静态,所以任何实例都可以直接引用它。

  • 将处理程序在一些其他全球可用的对象(静态,单例等)中,所以两个消费者都可以使用它

  • 使用提供事件聚合的框架,所以你不必担心这样的事情。 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