我是一个C#的新手,弄了一个闹钟的小程序。原来只有小时,分钟,秒,只能提示当天要做的事情。我给完善了下,想把它弄成可以选择任意一天任意时刻提示的。经过修改后当天都不提示了,请大侠帮忙啊,看看什么地方出了问题啊?
感激不盛啊!!!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace AlarmClock
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MonthCalendar monthCalendar1;
private AxMSMask.AxMaskEdBox mask1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button buttonadd;
private System.Windows.Forms.Button buttondel;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.DateTimePicker dateTimePicker1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.label1 = new System.Windows.Forms.Label();
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
this.mask1 = new AxMSMask.AxMaskEdBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.buttonadd = new System.Windows.Forms.Button();
this.buttondel = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
((System.ComponentModel.ISupportInitialize)(this.mask1)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 32);
this.label1.TabIndex = 0;
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// monthCalendar1
//
this.monthCalendar1.Location = new System.Drawing.Point(112, 216);
this.monthCalendar1.Name = "monthCalendar1";
this.monthCalendar1.TabIndex = 1;
this.monthCalendar1.DateChanged += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateSelected);
//
// mask1
//
this.mask1.Location = new System.Drawing.Point(24, 56);
this.mask1.Name = "mask1";
this.mask1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("mask1.OcxState")));
this.mask1.Size = new System.Drawing.Size(112, 23);
this.mask1.TabIndex = 2;
this.mask1.Change += new System.EventHandler(this.mask1_Change);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(24, 96);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(112, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "输入内容";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(168, 16);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(240, 136);
this.listBox1.TabIndex = 4;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// buttonadd
//
this.buttonadd.Location = new System.Drawing.Point(184, 176);
this.buttonadd.Name = "buttonadd";
this.buttonadd.TabIndex = 5;
this.buttonadd.Text = "添加";
this.buttonadd.Click += new System.EventHandler(this.buttonadd_Click);
//
// buttondel
//
this.buttondel.Location = new System.Drawing.Point(312, 176);
this.buttondel.Name = "buttondel";
this.buttondel.TabIndex = 6;
this.buttondel.Text = "删除";
this.buttondel.Click += new System.EventHandler(this.buttondel_Click);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(24, 144);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(112, 21);
this.dateTimePicker1.TabIndex = 7;
this.dateTimePicker1.Value = new System.DateTime(2007, 3, 28, 17, 38, 0, 0);
this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(456, 366);
this.Controls.Add(this.dateTimePicker1);
this.Controls.Add(this.buttondel);
this.Controls.Add(this.buttonadd);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.mask1);
this.Controls.Add(this.monthCalendar1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "小闹钟";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.mask1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void timer1_Tick(object sender, System.EventArgs e)
{
label1.Text=System.DateTime.Now.ToLongTimeString();
int i;
int hh= DateTime.Now.Hour;
int mm = DateTime.Now.Minute;
int ss = DateTime.Now.Second;
int yy = DateTime.Now.Year;
int month = DateTime.Now.Month;
int dd = DateTime.Now.Day;
for (i=1; i <= listBox1.Items.Count; i++)
{
string mytime,datestring,datestring1;
int myhh, mymm, myss,myyy,mydd;
int mymonth;
mytime = listBox1.Items[i-1].ToString();
datestring1=dateTimePicker1.Value.ToShortDateString();
datestring=datestring1.Replace("-","");
myhh = int.Parse(mytime.Substring(0,2));
if (hh==myhh)
{
mymm = int.Parse(mytime.Substring(2,2));
if (mm == mymm)
{
myss=int.Parse(mytime.Substring(4,2));
if (ss==myss)
{
myyy=int.Parse(datestring.Substring(0,4));
if (yy==myyy)
{
mymonth=int.Parse(datestring.Substring(4,2));
if(month==mymonth)
{
mydd=int.Parse(datestring.Substring(6,2));
string tempmsg = mytime.Substring(15,mytime.Length-15);
MessageBox.Show(tempmsg,"闹钟提示");
}
}
}
}
}
}
}
private void mask1_Change(object sender, System.EventArgs e)
{
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void buttonadd_Click(object sender, System.EventArgs e)
{
String tempstr;
int tss, tmm, thh;
tempstr = mask1.ClipText;
if (tempstr.Length < 6)
{
MessageBox.Show("输入格式错误, 不足位请补0","格式错误");
mask1.Focus();
mask1.SelStart=0;
mask1.SelLength=8;
return;}
thh=int.Parse(tempstr.Substring(0,2));
if (thh<0 || thh>23)
{
MessageBox.Show("输入小时数应在0到23之间","小时数错误");
mask1.Focus();
mask1.SelStart=0;
mask1.SelLength=2;
return;}
tmm=int.Parse(tempstr.Substring(2,2));
if (tmm<0 || tmm>60)
{
MessageBox.Show("输入分钟数应在0到60之间","分钟数错误");
mask1.Focus();
mask1.SelStart=3;
mask1.SelLength=2;
return;}
tss=int.Parse(tempstr.Substring(4,2));
if (tss<0 || thh>60)
{
MessageBox.Show("输入秒钟数应在0到60之间","秒钟数错误");
mask1.Focus();
mask1.SelStart=6;
mask1.SelLength=2;
return;}
tempstr=tempstr+"-"+textBox1.Text+"-"+dateTimePicker1.Value.ToShortDateString();
listBox1.Items.Add(tempstr);
textBox1.Text=" ";
}
private void label1_Click(object sender, System.EventArgs e)
{
}
private void buttondel_Click(object sender, System.EventArgs e)
{
if (listBox1.Items.Count>0)
{
if (listBox1.SelectedItems.Count>0)
{listBox1.Items.RemoveAt(listBox1.SelectedIndex);}
}
}
private void monthCalendar1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void dateTimePicker1_ValueChanged(object sender, System.EventArgs e)
{
}
}
}