小铃初闹C#初学者(二)
来源:互联网 发布:网络公关公司ymjrkj 编辑:程序博客网 时间:2024/05/16 01:58
小铃初闹C#初学者(二)
【技术要点】
——NotifyIcon控件,显示在后台运行进程的标志。
ShowBalloonTip方法,在任务栏中显示气泡提示。
public voidShowBalloonTip (int timeout, string tipTitle, string tipText, ToolTipIcontipIcon);
【实现步骤】
——界面
打开WindowsFormsApplication1项目在Form1窗体中添加NotifyIcon控件,选择Icon图标后再添加Timer控件,修改Interval值为500。
——代码
双击Timer2组件输入Timer2_Tick事件代码
if (flag ==false){//比较托盘图标标志
notifyIcon1.Visible =true;//托盘图标显示
notifyIcon1.ShowBalloonTip(1000, "时间到", DateTime.Now.ToLocalTime().ToString(),ToolTipIcon.Info);//任务栏气泡提示
flag = true;}
else{notifyIcon1.Visible=false;//托盘图标隐藏
flag = false;}
将Timer1_Tick事件中的label1.Text = "到达计时点"替换为代码
timer2.Enabled = true;//启动timer2
在notifyIcon1_BalloonTipClicked事件中加入代码
timer1.Enabled = true;//启动timer1
timer2.Enabled = false;//暂停timer2
当然在class Form1中加入代码
public static bool flag = false;//表示托盘图标是否闪烁
——完善
添加textBox2控件后改写Timer2_Tick中代码实现文字说明显示
DateTime.Now.ToLocalTime().ToString()为textBox2.Text.ToString()
为防止空字符在Form1_Load事件中加入代码
textBox2.Text = "_";//防止空字符
——改进
可多任务连续提醒。
【主要代码】
public static bool flag = false;//表示托盘图标是否闪烁
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
string get_time = DateTime.Now.ToString ();//保存当前时间
string set_time = textBox1.Text.ToString ();//从textBox1获得目标时间
//比较当前与目标时间
if (get_time == set_time)
{
timer1.Enabled = false;//暂停timer1
timer2.Enabled = true;//启动timer2
}
else
{
label1.Text = get_time;//在label1显示当前时间
}
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = DateTime.Now.ToString ()+".";//用符号区别输入
textBox2.Text = "_";//防止空字符
timer1.Enabled = true;//启动timer1
}
private void timer2_Tick(object sender, EventArgs e)
{
//比较托盘图标标志
if (flag == false)
{
notifyIcon1.Visible =true;//托盘图标显示
notifyIcon1.ShowBalloonTip(1000, "时间到",textBox2.Text.ToString(), ToolTipIcon.Info);//任务栏气泡提示
flag = true;
}
else
{
notifyIcon1.Visible =false;//托盘图标隐藏
flag = false;
}
}
private void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
{
timer1.Enabled = true;//启动timer1
timer2.Enabled = false;//暂停timer2
}
- 小铃初闹C#初学者(二)
- wxpython初学者(二)
- c#文件操作(初学者)
- Oracle初学者笔记(二)
- latex初学者入门(二)
- 初学者学数据结构(二)
- 初学者学Java(二)
- java初学者(二)继承
- C#调用DLL (初学者适用)
- C# Socket实例(适合初学者)
- C#初学者的那些事(一)
- C#邮件发送详解(适合初学者)
- C#获取网络时间(初学者)
- TIJ swot_JAVA的初学者(二)
- Sysbian UIQ 初学者学习引导(二)
- PHP初学者头疼问题总结(二)
- .NET初学者架构设计指南(二)
- Java初学者看看.二(转载)
- java swing 小结
- WARNING: inbound connection timed out (ORA-3136)连接超时问题
- Google SEO优化技术的12个要点总结
- swfupload使用中遇到问题处理方法
- 原因分析与解决方案的实战演练
- 小铃初闹C#初学者(二)
- 关于HTML5的11个让人难以接受的事实
- dorado7 Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
- 醍醐灌顶:作为创业者,如何熬过第一年
- Ubuntu 共享文件
- 推荐一本书——《漫谈设计模式——从面向对象开始》(有电子版)
- Fedora16下Grub2的配置
- (转)Linux平台用C++封装线程读写锁
- 待验证