⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alarmform.cs

📁 中文名:Windows Forms 程序设计 英文名:Windows Forms Programming in c# 作者: Chris Sells 翻译: 荣耀 蒋贤哲 出版社:人民
💻 CS
字号:
#region Using directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

#endregion

namespace TimerComponentSample {
  partial class AlarmForm : Form {
    public AlarmForm() {
      InitializeComponent();

      //// Configure the Timer component
      //this.timer.Enabled = true;
      //this.timer.Interval = 1000;
      //this.timer.Tick += this.timer_Tick;
    }

    DateTime alarm = DateTime.MaxValue; // No alarm

    private void setAlarmButton_Click(object sender, EventArgs e) {
      alarm = this.dateTimePicker.Value;
    }

    private void timer_Tick(object sender, EventArgs e) {
      // Check to see whether we're within 1 second of the alarm
      double seconds = (DateTime.Now - alarm).TotalSeconds;
      if( (seconds >= 0) && (seconds <= 1) ) {
        this.alarm = DateTime.MaxValue; // Show alarm only once
        MessageBox.Show("Wake Up!");
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -