我过去在VB6中用过,方法很简单
PUBLIC EVENT eventA(parameter)使用的时候
RaiseEvent eventA(haha)就可以了,在网络上找了点C#的事件文章,什么托管什么的,搞得有点晕晕的。大家帮个忙,简单点的,我要做个控件,类里面声明事件,触发,类外添加相关事件处理代码。多谢了。。

解决方案 »

  1.   


    using System;//定义委托
    public delegate void MyDelegate();   public class MyClass
    {
       //定义事件
       public event MyDelegate MyEvent;   //触发事件
       public void FireAway() 
       {
          if (MyEvent != null)
             MyEvent();
       }
    }
    public class MainClass 
    {
       //被挂钩到事件的方法
       static private void f() 
       {
          Console.WriteLine("This is called when the event fires.");
       }   //挂钩事件
       static public void Main () 
       {
          MyClass i = new MyClass();      i.MyEvent += new MyDelegate(f);
          i.FireAway();
       }
    }
      

  2.   

    C#中说事件基本上离不开delegate(委托)的。