winform倒計時


public partial class Form1 : Form
    {
        private int Seconds;
        public Form1()
        {
            InitializeComponent();
       // 任務欄是否顯示
this.ShowInTaskbar = false; timer1.Interval = 1000; timer1.Enabled = false; // 定時間隔:25分鍾 Seconds = 60 * 60; ShowTime(); } private void button1_Click(object sender, EventArgs e) {
        // 倒計時開始 timer1.Start(); }
private void ShowTime() { // 顯示剩余時間 label1.Text = string.Format("{0:d2}:{1:d2}", Seconds / 60, Seconds % 60); } private void timer1_Tick(object sender, EventArgs e) { Seconds--; if (Seconds < 0) { // 停止倒計時 timer1.Stop(); if (WindowState == FormWindowState.Minimized) { //還原窗體顯示 this.Show(); WindowState = FormWindowState.Normal; //激活窗體並給予它焦點 this.Activate(); //任務欄區顯示圖標 //this.ShowInTaskbar = true; //托盤區圖標隱藏 notifyIcon1.Visible = false; } return; } ShowTime(); } private void label1_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { Seconds = 60 * 60; ShowTime(); } private void Form1_Load(object sender, EventArgs e) { } private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) {
        // 托盤圖標的雙擊事件
this.Show(); //還原窗體顯示 this.WindowState = FormWindowState.Normal; this.Activate(); //任務欄區顯示圖標 //this.ShowInTaskbar = true; //托盤區圖標隱藏 notifyIcon1.Visible = false; } private void Form1_Deactivat(object sender, EventArgs e) {
        //借助失去焦點事件判斷窗口最小化
if (this.WindowState == FormWindowState.Minimized) { this.notifyIcon1.Visible = true; this.Hide(); this.ShowInTaskbar = false; } } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM