[英]c# notifications in taskbar windows7
我想在c#winforms中编写一个简单的程序,它在一个固定的时间内(例如在13:00和21:00)显示给用户(在任务栏窗口7或10中)的通知。
我怎样才能做到这一点?
基本上,如果DateTime.Now
(当前小时)等于特定小时,则显示通知图标。
您应该在计时器/任务中运行此代码。
if (DateTime.Now.Hour == 13 && DateTime.Now.Minute == 00 || DateTime.Now.Hour == 21 && DateTime.Now.Minute == 00)
{
var notification = new System.Windows.Forms.NotifyIcon()
{
Visible = true,
Icon = System.Drawing.SystemIcons.Information,
BalloonTipText = "This is my notify icon",
};
notification.ShowBalloonTip(1000);
}
这应该做到......
Timer timer = new Timer();
public Form1()
{
InitializeComponent();
timer.Tick += Timer_Tick;
timer.Interval = 1000;
timer.Start();
}
int lastNotify = 0;
private void Timer_Tick(object sender, EventArgs e)
{
if ((DateTime.Now.Hour == 16 && lastNotify != 16) || (DateTime.Now.Hour == 21 && lastNotify != 21))
{
this.notifyIcon1.BalloonTipText = "Whatever";
this.notifyIcon1.BalloonTipTitle = "Title";
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(3);
lastNotify = DateTime.Now.Hour;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.