雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊:

本文實(shí)例講述了WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
namespace DemoDataGridView
{
 public partial class Form3 : Form, IMessageFilter
 {
  private int m_WaitMinute = 0;
  System.Windows.Forms.Timer MyTimer;
  public Form3()
  {
   InitializeComponent();
   MyTimer = new Timer();
   MyTimer.Interval = 1000;
   MyTimer.Tick += new EventHandler(MyTimer_Tick);
   Application.Idle += new EventHandler(Application_Idle);
  }
  void MyTimer_Tick(object sender, EventArgs e)
  {
   if (m_WaitMinute < 60)
   {
    MyTimer.Enabled = true;
    MyTimer.Interval = 10000; //10秒
    m_WaitMinute += 1;
    // this.Opacity = 1.0 - Convert.ToDouble(m_WaitMinute / 60.0);
   }
   else
   {
    MyTimer.Enabled = false;
   }
  }
  void Application_Idle(object sender, EventArgs e)
  {
   if (m_WaitMinute == 0)
   {
    System.IO.File.WriteAllText("D:\\1.txt", DateTime.Now.ToString());
    MyTimer.Start();
   }
   else
   {
    if (m_WaitMinute >= 6)
    {
     System.IO.File.WriteAllText("D:\\2.txt", DateTime.Now.ToString());
     this.Close();
    }
   }
  }
  public bool PreFilterMessage(ref Message m)
  {
   if (m_WaitMinute != 0)
   {
    m_WaitMinute = 0;
    MyTimer.Enabled = false;
    return true;
   }
   return false;
  }
 }
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

上一篇:C#調(diào)用dos窗口獲取相關(guān)信息的方法

欄    目:C#教程

下一篇:C#實(shí)現(xiàn)將窗體固定在顯示器的左上角且不能移動(dòng)的方法

本文標(biāo)題:WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法

本文地址:http://www.jygsgssxh.com/a1/C_jiaocheng/7016.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有