用c#制作有提示窗体的日程管理器。
以下为主窗体代码:
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.timers;
using system.data.oledb;
namespace calendar
{
/// <summary>
/// form1 的摘要说明。
/// </summary>
public class form1 : system.windows.forms.form
{
private system.windows.forms.tabcontrol tabcontrol1;
private system.windows.forms.tabpage first;
private system.windows.forms.tabpage tabpage1;
private system.windows.forms.button button1;
private system.windows.forms.button button2;
private system.windows.forms.button button3;
private system.windows.forms.button button4;
private system.windows.forms.button button5;
private system.windows.forms.textbox textbox1;
private system.windows.forms.textbox textbox2;
private system.windows.forms.label label1;
private system.windows.forms.label label2;
private system.windows.forms.label label3;
private system.windows.forms.groupbox groupbox1;
private system.windows.forms.textbox textbox3;
private system.windows.forms.tabpage tabpage2;
private system.windows.forms.tabpage tabpage3;
private system.windows.forms.timer timer1;
private system.windows.forms.textbox textbox4;
private system.data.oledb.oledbconnection myconn;
private system.data.oledb.oledbcommand mycmd;
private system.componentmodel.icontainer components;
public oledbdatareader dr;
public string info;
private system.windows.forms.textbox textbox5;
private system.windows.forms.checkedlistbox checkedlistbox1;
private system.windows.forms.label label4;
private system.windows.forms.textbox textbox6;
private system.data.oledb.oledbcommand insertcmd;
public datetime da;
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.tabcontrol1 = new system.windows.forms.tabcontrol();
this.tabpage1 = new system.windows.forms.tabpage();
this.textbox5 = new system.windows.forms.textbox();
this.groupbox1 = new system.windows.forms.groupbox();
this.textbox3 = new system.windows.forms.textbox();
this.label3 = new system.windows.forms.label();
this.label2 = new system.windows.forms.label();
this.label1 = new system.windows.forms.label();
this.textbox2 = new system.windows.forms.textbox();
this.textbox1 = new system.windows.forms.textbox();
this.button4 = new system.windows.forms.button();
this.button3 = new system.windows.forms.button();
this.first = new system.windows.forms.tabpage();
this.button5 = new system.windows.forms.button();
this.tabpage2 = new system.windows.forms.tabpage();
this.tabpage3 = new system.windows.forms.tabpage();
this.button1 = new system.windows.forms.button();
this.button2 = new system.windows.forms.button();
this.timer1 = new system.windows.forms.timer(this.components);
this.textbox4 = new system.windows.forms.textbox();
this.myconn = new system.data.oledb.oledbconnection();
this.mycmd = new system.data.oledb.oledbcommand();
this.checkedlistbox1 = new system.windows.forms.checkedlistbox();
this.label4 = new system.windows.forms.label();
this.textbox6 = new system.windows.forms.textbox();
this.insertcmd = new system.data.oledb.oledbcommand();
this.tabcontrol1.suspendlayout();
this.tabpage1.suspendlayout();
this.groupbox1.suspendlayout();
this.first.suspendlayout();
this.suspendlayout();
//
// tabcontrol1
//
this.tabcontrol1.controls.add(this.tabpage1);
this.tabcontrol1.controls.add(this.first);
this.tabcontrol1.controls.add(this.tabpage2);
this.tabcontrol1.controls.add(this.tabpage3);
this.tabcontrol1.location = new system.drawing.point(0, 0);
this.tabcontrol1.name = "tabcontrol1";
this.tabcontrol1.selectedindex = 0;
this.tabcontrol1.size = new system.drawing.size(392, 320);
this.tabcontrol1.tabindex = 0;
this.tabcontrol1.selectedindexchanged += new system.eventhandler(this.tabcontrol1_selectedindexchanged);
//
// tabpage1
//
this.tabpage1.controls.add(this.textbox5);
this.tabpage1.controls.add(this.groupbox1);
this.tabpage1.controls.add(this.label3);
this.tabpage1.controls.add(this.label2);
this.tabpage1.controls.add(this.label1);
this.tabpage1.controls.add(this.textbox2);
this.tabpage1.controls.add(this.textbox1);
this.tabpage1.controls.add(this.button4);
this.tabpage1.controls.add(this.button3);
this.tabpage1.location = new system.drawing.point(4, 22);
this.tabpage1.name = "tabpage1";
this.tabpage1.size = new system.drawing.size(384, 294);
this.tabpage1.tabindex = 1;
this.tabpage1.text = "添加提示";
//
// textbox5
//
this.textbox5.autosize = false;
this.textbox5.borderstyle = system.windows.forms.borderstyle.fixedsingle;
this.textbox5.location = new system.drawing.point(8, 256);
this.textbox5.name = "textbox5";
this.textbox5.readonly = true;
this.textbox5.size = new system.drawing.size(192, 22);
this.textbox5.tabindex = 8;
this.textbox5.text = "";
//
// groupbox1
//
this.groupbox1.controls.add(this.textbox6);
this.groupbox1.controls.add(this.label4);
this.groupbox1.controls.add(this.textbox3);
this.groupbox1.location = new system.drawing.point(8, 74);
this.groupbox1.name = "groupbox1";
this.groupbox1.size = new system.drawing.size(368, 160);
this.groupbox1.tabindex = 7;
this.groupbox1.tabstop = false;
this.groupbox1.text = "提示内容:";
//
// textbox3
//
this.textbox3.location = new system.drawing.point(8, 64);
this.textbox3.multiline = true;
this.textbox3.name = "textbox3";
this.textbox3.size = new system.drawing.size(352, 88);
this.textbox3.tabindex = 0;
this.textbox3.text = "";
//
// label3
//
this.label3.location = new system.drawing.point(64, 56);
this.label3.name = "label3";
this.label3.size = new system.drawing.size(304, 23);
this.label3.tabindex = 6;
this.label3.text = "例:2005-12-1 14:30:00";
//
// label2
//
this.label2.location = new system.drawing.point(215, 19);
this.label2.name = "label2";
this.label2.size = new system.drawing.size(48, 23);
this.label2.tabindex = 5;
this.label2.text = "时间:";
this.label2.textalign = system.drawing.contentalignment.topright;
//
// label1
//
this.label1.location = new system.drawing.point(8, 22);
this.label1.name = "label1";
this.label1.size = new system.drawing.size(56, 23);
this.label1.tabindex = 4;
this.label1.text = "日期:";
this.label1.textalign = system.drawing.contentalignment.topright;
//
// textbox2
//
this.textbox2.location = new system.drawing.point(270, 16);
this.textbox2.name = "textbox2";
this.textbox2.tabindex = 3;
this.textbox2.text = "";
//
// textbox1
//
this.textbox1.location = new system.drawing.point(72, 16);
this.textbox1.name = "textbox1";
this.textbox1.size = new system.drawing.size(136, 22);
this.textbox1.tabindex = 2;
this.textbox1.text = "";
this.textbox1.textchanged += new system.eventhandler(this.textbox1_textchanged);
//
// button4
//
this.button4.location = new system.drawing.point(296, 256);
this.button4.name = "button4";
this.button4.tabindex = 1;
this.button4.text = "取消";
this.button4.click += new system.eventhandler(this.button4_click);
//
// button3
//
this.button3.location = new system.drawing.point(208, 256);
this.button3.name = "button3";
this.button3.tabindex = 0;
this.button3.text = "添加";
this.button3.click += new system.eventhandler(this.button3_click);
//
// first
//
this.first.controls.add(this.checkedlistbox1);
this.first.controls.add(this.button5);
this.first.location = new system.drawing.point(4, 22);
this.first.name = "first";
this.first.size = new system.drawing.size(384, 294);
this.first.tabindex = 0;
this.first.text = "当前内容";
this.first.click += new system.eventhandler(this.first_click);
//
// button5
//
this.button5.location = new system.drawing.point(248, 256);
this.button5.name = "button5";
this.button5.tabindex = 1;
this.button5.text = "删除所选";
//
// tabpage2
//
this.tabpage2.location = new system.drawing.point(4, 22);
this.tabpage2.name = "tabpage2";
this.tabpage2.size = new system.drawing.size(384, 294);
this.tabpage2.tabindex = 2;
this.tabpage2.text = "其他";
//
// tabpage3
//
this.tabpage3.location = new system.drawing.point(4, 22);
this.tabpage3.name = "tabpage3";
this.tabpage3.size = new system.drawing.size(384, 294);
this.tabpage3.tabindex = 3;
this.tabpage3.text = "使用说明";
//
// button1
//
this.button1.location = new system.drawing.point(208, 328);
this.button1.name = "button1";
this.button1.tabindex = 1;
this.button1.text = "确定";
this.button1.click += new system.eventhandler(this.button1_click_1);
//
// button2
//
this.button2.location = new system.drawing.point(296, 328);
this.button2.name = "button2";
this.button2.tabindex = 2;
this.button2.text = "退出";
this.button2.click += new system.eventhandler(this.button2_click);
//
// timer1
//
this.timer1.enabled = true;
this.timer1.interval = 1000;
this.timer1.tick += new system.eventhandler(this.timer1_tick);
//
// textbox4
//
this.textbox4.borderstyle = system.windows.forms.borderstyle.fixedsingle;
this.textbox4.location = new system.drawing.point(8, 328);
this.textbox4.name = "textbox4";
this.textbox4.readonly = true;
this.textbox4.size = new system.drawing.size(192, 22);
this.textbox4.tabindex = 3;
this.textbox4.text = "当前时间";
this.textbox4.wordwrap = false;
//
// myconn
//
this.myconn.connectionstring = @"jet oledb:global partial bulk ops=2;jet oledb:registry path=;jet oledb:database locking mode=1;jet oledb:database password=;data source=""f:/visual studio projects/calendar/bin/debug/calendar.mdb"";password=;jet oledb:engine type=5;jet oledb:global bulk transactions=1;provider=""microsoft.jet.oledb.4.0"";jet oledb:system database=;jet oledb:sfp=false;extended properties=;mode=share deny none;jet oledb:new database password=;jet oledb:create system database=false;jet oledb:don't copy locale on compact=false;jet oledb:compact without replica repair=false;user id=admin;jet oledb:encrypt database=false";
//
// mycmd
//
this.mycmd.commandtext = "select calendar.*, [datetime] as expr1, info as expr2 from calendar order by id";
this.mycmd.connection = this.myconn;
//
// checkedlistbox1
//
this.checkedlistbox1.location = new system.drawing.point(6, 16);
this.checkedlistbox1.name = "checkedlistbox1";
this.checkedlistbox1.size = new system.drawing.size(376, 225);
this.checkedlistbox1.tabindex = 3;
//
// label4
//
this.label4.location = new system.drawing.point(16, 24);
this.label4.name = "label4";
this.label4.size = new system.drawing.size(48, 23);
this.label4.tabindex = 1;
this.label4.text = "标题:";
this.label4.textalign = system.drawing.contentalignment.topright;
//
// textbox6
//
this.textbox6.location = new system.drawing.point(72, 24);
this.textbox6.name = "textbox6";
this.textbox6.size = new system.drawing.size(184, 22);
this.textbox6.tabindex = 2;
this.textbox6.text = "";
//
// insertcmd
//
this.insertcmd.connection = this.myconn;
//
// form1
//
this.autoscalebasesize = new system.drawing.size(7, 15);
this.clientsize = new system.drawing.size(392, 363);
this.controls.add(this.textbox4);
this.controls.add(this.button2);
this.controls.add(this.button1);
this.controls.add(this.tabcontrol1);
this.icon = ((system.drawing.icon)(resources.getobject("$this.icon")));
this.maximizebox = false;
this.name = "form1";
this.text = "calendar by sinory studio";
this.load += new system.eventhandler(this.form1_load);
this.tabcontrol1.resumelayout(false);
this.tabpage1.resumelayout(false);
this.groupbox1.resumelayout(false);
this.first.resumelayout(false);
this.resumelayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[stathread]
static void main()
{
application.run(new form1());
}
private void form1_load(object sender, system.eventargs e)
{
this.timer1.enabled=true;//设置timer控件的属性
select();//从数据库中读取最近的一次提示
}
private void button1_click(object sender, system.eventargs e)
{
}
private void tabcontrol1_selectedindexchanged(object sender, system.eventargs e)
{
}
private void button2_click(object sender, system.eventargs e)
{
this.close();//退出
}
private void first_click(object sender, system.eventargs e)
{
}
private void textbox1_textchanged(object sender, system.eventargs e)
{
}
private void select()
{
datetime dn=datetime.now;
datetime datetime;
myconn.open();
dr=mycmd.executereader();
string title,id;
da=datetime.parse("3000-1-1 01:01:01");//设一个大点的值
while(dr.read())//读取数据库
{
datetime=datetime.parse(dr["datetime"].tostring());
id=dr["id"].tostring();
title=dr["title"].tostring();
this.checkedlistbox1.items.add(id+" "+datetime.tostring()+" "+title);
if(datetime>dn&&datetime<da)
{
da=datetime;//取值
info=dr["info"].tostring();
}
}
dr.close();
myconn.close();//关闭数据库
this.textbox5.text="next:"+da.tostring();//显示最近的一次提示的时间
}
private void button1_click_1(object sender, system.eventargs e)
{
this.hide();//主窗体隐藏
}
private void timer1_tick(object sender, system.eventargs e)
{
//接收当前日期和时间,用于即时显示
string currtime=system.datetime.now.tostring();
this.textbox4.text="当前时间:"+currtime;
if(datetime.parse(currtime)==da)
{
clew clew1=new clew();//设置提示窗体的属性
clew1.heightmax=150;
clew1.widthmax=180;
clew1.info=info;
clew1.scrollshow();
select();
}
}
private void button4_click(object sender, system.eventargs e)
{
this.textbox1.text="";
this.textbox2.text="";
this.textbox3.text="";
this.textbox6.text="";
}
private void button3_click(object sender, system.eventargs e)
{
if(this.textbox1.text!=""&&this.textbox2.text!=""&&this.textbox3.text!=""&&this.textbox6.text!="")
{
string indate=this.textbox1+" "+this.textbox2.text;
insertcmd.commandtext="insert into calendar(datetime,info,title) values('"+indate+"','"+this.textbox3.tostring()+"','"+this.textbox6.tostring()+"')";
myconn.open();
insertcmd.executenonquery();
myconn.close();
select();
messagebox.show("添加成功!!");
}
else
{
messagebox.show("请按指定格式填写并且各项不能为空!!");
}
}
}
}
以下为提示窗体代码:
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
namespace calendar
{
/// <summary>
/// clew 的摘要说明。
/// </summary>
public class clew : system.windows.forms.form
{
private system.windows.forms.timer timer1;
private system.windows.forms.timer timer2;
private system.windows.forms.timer timer3;
private system.windows.forms.label label1;
private system.windows.forms.label label2;
private system.componentmodel.icontainer components;
public clew()
{
//
// 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();
this.timer1 = new system.windows.forms.timer(this.components);
this.timer2 = new system.windows.forms.timer(this.components);
this.timer3 = new system.windows.forms.timer(this.components);
this.label1 = new system.windows.forms.label();
this.label2 = new system.windows.forms.label();
this.suspendlayout();
//
// timer1
//
this.timer1.interval = 10;
this.timer1.tick += new system.eventhandler(this.timer1_tick);
//
// timer2
//
this.timer2.interval = 10;
this.timer2.tick += new system.eventhandler(this.timer2_tick);
//
// timer3
//
this.timer3.interval = 10;
this.timer3.tick += new system.eventhandler(this.timer3_tick);
//
// label1
//
this.label1.location = new system.drawing.point(24, 40);
this.label1.name = "label1";
this.label1.size = new system.drawing.size(152, 96);
this.label1.tabindex = 0;
//
// label2
//
this.label2.location = new system.drawing.point(0, 0);
this.label2.name = "label2";
this.label2.size = new system.drawing.size(192, 24);
this.label2.tabindex = 1;
//
// clew
//
this.autoscalebasesize = new system.drawing.size(7, 15);
this.backcolor = system.drawing.systemcolors.inactivecaption;
this.clientsize = new system.drawing.size(194, 150);
this.controls.add(this.label2);
this.controls.add(this.label1);
this.cursor = system.windows.forms.cursors.hand;
this.forecolor = system.drawing.systemcolors.activecaptiontext;
this.formborderstyle = system.windows.forms.formborderstyle.fixedtoolwindow;
this.maximizebox = false;
this.minimizebox = false;
this.name = "clew";
this.showintaskbar = false;
this.text = "提示……";
this.topmost = true;
this.load += new system.eventhandler(this.clew_load);
this.resumelayout(false);
}
#endregion
private string info;//设置提示窗体的内容;
public string info
{
set
{
info=value;
}
get
{
return info;
}
}
private int heightmax, widthmax;//设置窗体显示的大小的属性
public int heightmax
{
set
{
heightmax = value;
}
get
{
return heightmax;
}
}
public int widthmax
{
set
{
widthmax = value;
}
get
{
return widthmax;
}
}
public void scrollshow()
{
this.width = widthmax;
this.height = 0;
this.show();
this.timer1.enabled = true;
}
public int staytime = 5000;//窗体的停留时间
//窗体的滚出与滚入方法
private void scrollup()
{
if(height < heightmax)
{
this.height += 3;
this.location = new point(this.location.x, this.location.y - 3);
}
else
{
this.timer1.enabled = false;
this.timer2.enabled = true;
}
}
private void scrolldown()
{
if(height > 3)
{
this.height -= 3;
this.location = new point(this.location.x, this.location.y + 3);
}
else
{
this.timer3.enabled = false;
this.close();
}
}
private void clew_load(object sender, system.eventargs e)
{
string dnow;
dnow=datetime.now.toshorttimestring().tostring();
this.label2.text="现在时刻是:"+dnow;
this.label1.text=info;
screen[] screens = screen.allscreens;
screen screen = screens[0];//获取屏幕变量
this.location = new point(screen.workingarea.width - widthmax - 20, screen.workingarea.height - 34);//workingarea为windows桌面的工作区
this.timer2.interval = staytime;
}
private void timer1_tick(object sender, system.eventargs e)
{
scrollup();
}
private void timer2_tick(object sender, system.eventargs e)
{
timer2.enabled = false;
timer3.enabled = true;
}
private void timer3_tick(object sender, system.eventargs e)
{
scrolldown();
}
}
}
//由于是从vs2003下编的所以这些代码不能直接运行,但可以提供一个思路,另外还可以加个托盘图标或,其他小功能。
新闻热点
疑难解答