📄 setalarm.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace MyClock
{
/// <summary>
/// SetAlarm 的摘要说明。
/// </summary>
public class SetAlarm : System.Windows.Forms.Form
{
private System.Windows.Forms.DateTimePicker dateTimePicker1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ComboBox comboTask;
private System.Windows.Forms.CheckBox checkBoxSound;
private System.Windows.Forms.CheckBox checkBoxMsg;
private System.Windows.Forms.TextBox txtMsg;
private string AlarmTime , AlarmDate , MsgText , TaskName ;
private bool AlarmEveryDay , bSound , bMsgBox ;
private System.Windows.Forms.DateTimePicker dateTimePicker2;
private System.Windows.Forms.CheckBox checkBoxEveryDay;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.CheckBox checkAutoHide;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public SetAlarm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
LoadAlarm();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker();
this.checkBoxEveryDay = new System.Windows.Forms.CheckBox();
this.txtMsg = new System.Windows.Forms.TextBox();
this.checkBoxMsg = new System.Windows.Forms.CheckBox();
this.checkBoxSound = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.comboTask = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.checkAutoHide = new System.Windows.Forms.CheckBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.label2 = new System.Windows.Forms.Label();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 21);
this.label1.TabIndex = 1;
this.label1.Text = "日期时间:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(96, 16);
this.dateTimePicker1.MaxDate = new System.DateTime(2010, 12, 31, 0, 0, 0, 0);
this.dateTimePicker1.MinDate = new System.DateTime(2002, 1, 1, 0, 0, 0, 0);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(120, 21);
this.dateTimePicker1.TabIndex = 0;
//
// dateTimePicker2
//
this.dateTimePicker2.CustomFormat = "";
this.dateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Time;
this.dateTimePicker2.Location = new System.Drawing.Point(96, 48);
this.dateTimePicker2.MaxDate = new System.DateTime(2010, 12, 31, 0, 0, 0, 0);
this.dateTimePicker2.MinDate = new System.DateTime(2002, 1, 1, 0, 0, 0, 0);
this.dateTimePicker2.Name = "dateTimePicker2";
this.dateTimePicker2.ShowUpDown = true;
this.dateTimePicker2.Size = new System.Drawing.Size(120, 21);
this.dateTimePicker2.TabIndex = 7;
//
// checkBoxEveryDay
//
this.checkBoxEveryDay.Location = new System.Drawing.Point(16, 16);
this.checkBoxEveryDay.Name = "checkBoxEveryDay";
this.checkBoxEveryDay.TabIndex = 7;
this.checkBoxEveryDay.Text = "每天定时执行";
//
// txtMsg
//
this.txtMsg.Location = new System.Drawing.Point(96, 112);
this.txtMsg.MaxLength = 200;
this.txtMsg.Name = "txtMsg";
this.txtMsg.Size = new System.Drawing.Size(136, 21);
this.txtMsg.TabIndex = 6;
this.txtMsg.Text = "提示信息 ,50字以内......";
//
// checkBoxMsg
//
this.checkBoxMsg.Checked = true;
this.checkBoxMsg.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxMsg.Location = new System.Drawing.Point(16, 72);
this.checkBoxMsg.Name = "checkBoxMsg";
this.checkBoxMsg.TabIndex = 5;
this.checkBoxMsg.Text = "弹出提醒窗口";
//
// checkBoxSound
//
this.checkBoxSound.Checked = true;
this.checkBoxSound.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxSound.Location = new System.Drawing.Point(136, 16);
this.checkBoxSound.Name = "checkBoxSound";
this.checkBoxSound.TabIndex = 4;
this.checkBoxSound.Text = "声音提示";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 80);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(72, 21);
this.label5.TabIndex = 3;
this.label5.Text = "任务内容:";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// comboTask
//
this.comboTask.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboTask.Items.AddRange(new object[] {
"闹钟",
"关机",
"重启"});
this.comboTask.Location = new System.Drawing.Point(96, 80);
this.comboTask.Name = "comboTask";
this.comboTask.Size = new System.Drawing.Size(120, 20);
this.comboTask.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 192);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(184, 192);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// checkAutoHide
//
this.checkAutoHide.Location = new System.Drawing.Point(136, 72);
this.checkAutoHide.Name = "checkAutoHide";
this.checkAutoHide.Size = new System.Drawing.Size(112, 24);
this.checkAutoHide.TabIndex = 8;
this.checkAutoHide.Text = "自动隐藏提醒窗";
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(16, 120);
this.radioButton1.Name = "radioButton1";
this.radioButton1.TabIndex = 9;
this.radioButton1.Text = "MSN样式提醒窗";
//
// radioButton2
//
this.radioButton2.Checked = true;
this.radioButton2.Location = new System.Drawing.Point(136, 120);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(112, 24);
this.radioButton2.TabIndex = 10;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "卡通样式提醒窗";
//
// tabControl1
//
this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabPage1,
this.tabPage2});
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Top;
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(266, 184);
this.tabControl1.TabIndex = 10;
//
// tabPage1
//
this.tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label2,
this.dateTimePicker1,
this.dateTimePicker2,
this.label1,
this.comboTask,
this.txtMsg,
this.label5});
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(258, 159);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "任务时间及内容";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 112);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 21);
this.label2.TabIndex = 8;
this.label2.Text = "提示信息:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// tabPage2
//
this.tabPage2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.checkBoxEveryDay,
this.checkBoxSound,
this.checkBoxMsg,
this.checkAutoHide,
this.radioButton2,
this.radioButton1});
this.tabPage2.Location = new System.Drawing.Point(4, 21);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(258, 159);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "设置";
//
// SetAlarm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(266, 223);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl1,
this.button2,
this.button1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SetAlarm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "定时任务";
this.TopMost = true;
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
AlarmDate = this.dateTimePicker1 .Value .ToShortDateString () ;
AlarmTime = this.dateTimePicker2 .Value .ToShortTimeString ();
TaskName = this.comboTask .SelectedItem .ToString ();
AlarmEveryDay = this.checkBoxEveryDay .Checked ;
bSound = this.checkBoxSound .Checked ;
bMsgBox = this.checkBoxMsg .Checked ;
MsgText = this.txtMsg .Text ;
if(CheckForm())
{
SaveAlarm();
this.Close ();
}
}
private bool CheckForm()
{
if(Convert.ToDateTime (AlarmDate)<DateTime.Today && checkBoxEveryDay .Checked == false )
{
MessageBox.Show ("您选择的日期已经过了,请重新选择!!");
return false ;
}
if(Convert.ToDateTime (AlarmTime)<=DateTime.Now && Convert.ToDateTime (AlarmDate)<=DateTime.Today)
{
MessageBox.Show ("您选择的时间已经过了,请重新选择!!");
return false ;
}
return true ;
}
private void SaveAlarm()
{
string path = Application.StartupPath ;
Ini ini = new Ini(path+"\\Set.ini");
ini.IniWriteValue ("Alarm","AlarmDate",AlarmDate);
ini.IniWriteValue ("Alarm","AlarmTime",AlarmTime);
ini.IniWriteValue ("Alarm","AlarmEveryDay",AlarmEveryDay.ToString ());
ini.IniWriteValue ("Alarm","bSound",bSound.ToString ());
ini.IniWriteValue ("Alarm","bMsgBox",bMsgBox.ToString ());
ini.IniWriteValue ("Alarm","TaskName",this.comboTask .SelectedItem .ToString ());
ini.IniWriteValue ("Alarm","MsgText",MsgText);
if(this.radioButton1 .Checked )
ini.IniWriteValue ("MsgForm","Type","MSN");
else
ini.IniWriteValue ("MsgForm","Type","katong");
ini.IniWriteValue ("MsgForm","AutoHide",this.checkAutoHide .Checked .ToString ());
}
private void LoadAlarm()
{
string path = Application.StartupPath ;
Ini ini = new Ini(path+"\\Set.ini");
this.dateTimePicker1 .Value = Convert.ToDateTime (ini.IniReadValue ("Alarm","AlarmDate"));
this.dateTimePicker2 .Value = Convert.ToDateTime (ini.IniReadValue ("Alarm","AlarmTime"));
this.checkBoxEveryDay.Checked = Convert.ToBoolean (ini.IniReadValue ("Alarm","AlarmEveryDay"));
this.checkBoxSound.Checked = Convert.ToBoolean (ini.IniReadValue ("Alarm","bSound"));
this.checkBoxMsg.Checked = Convert.ToBoolean (ini.IniReadValue ("Alarm","bMsgBox"));
this.txtMsg.Text = ini.IniReadValue ("Alarm","MsgText");
if(ini.IniReadValue ("MsgForm","Type")=="MSN")
this.radioButton1 .Checked = true ;
else
this.radioButton2 .Checked = true ;
if(Convert.ToBoolean (ini.IniReadValue ("MsgForm","AutoHide")))
this.checkAutoHide .Checked = true ;
else
this.checkAutoHide .Checked = false ;
switch (ini.IniReadValue ("Alarm","TaskName"))
{
case "闹钟":
this.comboTask .SelectedIndex = 0 ;
break ;
case "关机":
this.comboTask .SelectedIndex = 1 ;
break ;
case "重启":
this.comboTask .SelectedIndex = 2 ;
break ;
default :
this.comboTask .SelectedIndex = 0 ;
break;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -