0

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#?

MinimalTech
  • 881
  • 3
  • 8
  • 23
  • what other apps? can you provide an example? – Daniel A. White Jun 01 '20 at 14:02
  • There's a Registry setting, in the CurrentUser branch, that could enable it: `HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced`, setting `EnableBalloonTips = 1` (`DWORD` - to be added, if it's not there). Then broadcast the setting change. Actually, I'm not sure whether broadcasting can activate the feature. Maybe a reboot is needed instead. Anyway, is that really important? – Jimi Jun 01 '20 at 14:10
  • @DanielA.White sorry, my mistake! I am editing my question now... I mistakenly thought that an app was giving me a BalloonTip instead of a Toast, but I tested it again and it gave me a Toast notification... – MinimalTech Jun 01 '20 at 14:15
  • i would just implement your own - if thats what you really want. i wouldn't break from what windows gives you however... – Daniel A. White Jun 01 '20 at 14:23
  • @Jimi the problem is that the app must also work on machines that joins a Windows domain and have domain's Group Policy. I think it is important because the BalloonTip is more clearer to a user - someone can easily understand by which tray icon the tooltip was originated from – MinimalTech Jun 01 '20 at 14:24
  • @DanielA.White can I implement my own? Can I make it look the same as the classic BalloonTip? How? – MinimalTech Jun 01 '20 at 14:25
  • you can do whatever you want - windows provides a trove of apis for drawing things. – Daniel A. White Jun 01 '20 at 14:26
  • @DanielA.White can you provide a workaround for this specific matter? – MinimalTech Jun 01 '20 at 14:27
  • 1
    @MinimalTech i would ask yourself and share the answer to "why must i have balloon tips and not the windows 10 style"? my suggestion: go with the flow. – Daniel A. White Jun 01 '20 at 14:28
  • Do you have a Group Policy that explicitly disables them? In this case, you're simply not supposed to show balloons :) -- The Toast is as informative as you make it. Add information that specify what app/service is showing the notification. – Jimi Jun 01 '20 at 14:29
  • @Jimi the problem is that the Toast shows only 4 lines in description. Also, it is not staying visible for over 2-3 seconds. Also, when someone clicks it, it does nothing to indicate the tray icon which has originated it! Do you have a suggestion which improves this? All I want to do, is to help any unfamiliar User to understand what to do with my app, not to add more difficulties or old-style effects to it... – MinimalTech Jun 01 '20 at 14:39
  • I'd take Daniel A.White's hint and *go with the flow*. Which may also mean to implement (explicitly) Toast Notifications in your WinForms app: [Send a local toast notification from desktop C# apps](https://learn.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast-desktop). Note that from Windows 10 1903 the process is simplified, but, IMO, you should consider also older versions. User should be instructed on the use of the Action Center. – Jimi Jun 01 '20 at 14:51
  • See also [Call Windows Runtime APIs in desktop apps](https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance) and the answers [here](https://stackoverflow.com/q/39139369/7444103) – Jimi Jun 01 '20 at 14:54
  • @Jimi I looked at the link you posted! Thank you! But it is a real pain to implement all these functions in the app to achieve just a better Toast Notification! Is there any (free-to-use) framework that handles all these nicely? – MinimalTech Jun 01 '20 at 16:15
  • 1
    Because of the `INotificationActivationCallback`? Well, it's not that complicated. Anyway, you can try [this one](https://github.com/CHDKUtil/DesktopToast). A Google/Bing/Whatever or NUGet Package Manager search may give back more. One of the answers I linked deals with Windows 10 SDK targeting issues, just in case. – Jimi Jun 01 '20 at 16:38

1 Answers1

0

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

D J
  • 845
  • 1
  • 13
  • 27
  • @MinimialTech: Whenever you want to use this, add a form to your project and use this code. – D J Jun 02 '20 at 08:10
  • @MinimalTech : Pls check out the answer and mark it as the answer if it works for you. – D J Jun 03 '20 at 10:07