winform窗體失去焦點事件

方法一:1、在InitializeComponent函數中添加如下語句:

     this.Deactivate += new System.EventHandler(this.Form1_Deactivate);


2、在form1.cs中編寫以下函數:

    private void Form1_Deactivate(object sender, EventArgs e)

   {//添加你的代碼
   }


方法二:

        protected override void OnLostFocus(EventArgs e)
        {
           //添加你所需的代碼
            base.OnLostFocus(e);
        }


方法三:

1、在InitializeComponent函數中添加如下語句:

     this.LoseFocus += new System.EventHandler(this.Form1_LoseFocus);


2、在vform1.cs中編寫以下函數:

    private void Form1_LoseFucus(object sender, EventArgs e)

   {//添加你的代碼
   }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章