zoukankan      html  css  js  c++  java
  • 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; } } }

  • 相关阅读:
    PAT甲级——1095 Cars on Campus (排序、映射、字符串操作、题意理解)
    PAT甲级——1096 Consecutive Factors (数学题)
    PAT甲级——1097 Deduplication on a Linked List (链表)
    博客作业06--图
    博客作业05--查找
    博客作业04--树
    博客作业03--栈和队列
    博客作业2---线性表
    博客作业01-抽象数据类型
    C语言最后一次作业--总结报告
  • 原文地址:https://www.cnblogs.com/ziyandeyanhuo/p/10613318.html
Copyright © 2011-2022 走看看