定义事件

1、在类里面定义一个委托事件

    public partial class Form1 : Form
    {
        public delegate void CloseVideoHandler();

        public event CloseVideoHandler CloseVideoEvent; 
    }

2、在构造函数里添加事件处理方法

  public Form1()
   {
        InitializeComponent();

        this.CloseVideoEvent += Form1_CloseVideoEvent;
   }        

3、调用事件

    if (CloseVideoEvent != null)
    {
         this.CloseVideoEvent();
    }    

4、执行事件

void Form1_CloseVideoEvent()
        {

             this.BeginInvoke(new Action(delegate
                {
                    if (vpWindows != null && vpWindows.Text.Equals("大屏播放"))
                    {
                        System.Threading.Thread.Sleep(1000);
                        vpWindows.Dispose();
                        vpWindows.Close();
                    }
                }));
        }

 

posted on 2017-12-11 09:31  LJD泊水  阅读(207)  评论(0)    收藏  举报