0

I want to write a simple program in c# winforms, that shows a notifications to users (in task bar windows 7 or 10) in a constant time (for example in 13:00 and 21:00).

How can I do that?

Mark Kovak
  • 23
  • 6
  • Possible duplicate of [Creating a Popup Balloon like Windows Messenger or AVG](https://stackoverflow.com/questions/413656/creating-a-popup-balloon-like-windows-messenger-or-avg) – JayV Jun 13 '19 at 15:03
  • jayv where duplicate? my question is different. i don't need use buttons. but need sys.date. – Mark Kovak Jun 13 '19 at 15:04
  • The answer to that question shows how to use NotifyIcon, which, I think is what you are asking for as well – JayV Jun 13 '19 at 15:05

2 Answers2

1

Basically if DateTime.Now (current hour) equals a specific hour, show the notify icon.

You should run this code inside of a timer/task.

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);
}
Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73
Mikev
  • 2,012
  • 1
  • 15
  • 27
0

This should do it...

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