How to display a classic BalloonTip in system tray of Windows 10 instead of a Toast Notification in C#?

2.5k Views Asked by At

I am building a Windows Forms application for Windows, based on .Net 4.7.2 framework. The application is intended to work on Windows 10 plus Windows Server 2019 systems.

When a user minimizes the app and the app goes to tray, I want to display a classic BalloonTip on the top of it's tray icon, like this:

enter image description here

The problem is that when I do this:

    private void form1_Resize(object sender, EventArgs e)
    {

        if (this.WindowState == FormWindowState.Minimized)
        {
            this.Hide();
            trayIcon.Visible = true;
            trayIcon.ShowBalloonTip(8000);
        }

    }

my "BalloonTip" is displayed like this in the Windows 10 system I am working now:

enter image description here

I know that this is the new style of Windows 10. I am also informed about Windows Group Policy and it's registry settings. I do not want to change the policy of Windows.

EDIT: Also, the Toast Notification appears for only 2-3 seconds instead of 8 seconds I have set it...

How can I accomplish this in C#?

1

There are 1 best solutions below

2
D J On

Maybe, the Tulpep.NotificationWindow nuget package can work for you.

Pls have a look at this link : Foxlearn Notification

EDIT:

Create your own form for a custom Balloon Notification and use the below code.

Pls note that button1 is a little button in the top-right with a 'X' and is meant for close.

Next, add a pictureBox to your form, size it so as to fill the form and add the below image to the pictureBox : enter image description here

Then you can design the notification the way you want, add labels, pictureboxes, etc.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BubbleNotificationTest
{
    public partial class Form1 : Form
    {
        Timer t = new Timer();
        Timer fadeIn = new Timer();
        Timer fade = new Timer();
        public Form1()
        {
            InitializeComponent();
            Opacity = 0;
            fadeIn.Interval = 100;
            this.BackColor = Color.FromArgb(28, 28, 28);
            this.TransparencyKey = Color.FromArgb(28, 28, 28);
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(Screen.FromControl(this).Bounds.X + 850, Screen.FromControl(this).Bounds.Y + 662);
            fadeIn.Tick += new EventHandler(fadeIn_Tick);
            fadeIn.Start();
            t.Tick += new EventHandler(t_Tick);
            fade.Tick += new EventHandler(fade_Tick);
            fade.Interval = 100;
            t.Interval = 6000;
            t.Start();
        }

        private void fadeIn_Tick(object sender, EventArgs e)
        {
            this.Opacity += 0.05;
            if (this.Opacity == 1)
            {
                fadeIn.Stop();
            }
        }

        private void t_Tick(object sender, EventArgs e)
        {
            fade.Start();
        }

        private void fade_Tick(object sender, EventArgs e)
        {
            this.Opacity -= 0.05;
            if (this.Opacity == 0)
            {
                fade.Stop();
                this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

And here is the result : enter image description here