来自另一个DLL(或应用程序)的Fire DLL事件

时间:2013-02-19 16:19:48

标签: c# events dll

我有2个项目。在第一个:

public delegate _Event(int code);
public event _Event TestEvent;

现在我想在我的第二个项目中做这样的事情

public void TestFunc()
{
   TestEvent(11); //Project1.MyClass.TestEvent(11);
}

即我想触发Project1的事件表单Project2。有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

1.你在委托上缺少返回类型。

2.您只能在声明类型中触发事件。 你可以做的是在声明触发它的事件的类型上声明一个公共方法。

public delegate void _Event(int code);
public event _Event TestEvent;
public void FireEvent(int val){TestEvent(val);}
相关问题