Windows 7任务栏中的C#通知

时间:2019-06-13 14:59:35

标签: c# notifications taskbar

我想用c#winforms写一个简单的程序,该程序在固定的时间(例如13:00和21:00)向用户显示通知(在任务栏窗口7或10中)。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

基本上,如果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);
}

答案 1 :(得分:0)

这应该做...

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;
        }
    }