Question

I have a C# program that sits in the system tray and pops up a notification balloon now and then. I'd like to provide 2-3 buttons on the notification balloon to allow the user to take various actions when the notification appears - rather than, for example, having to click the notification balloon to display a form containing buttons for each possible action.

I'm looking for suggestions on the best way to go about implementing this.

Edit: clarification, I want to provide buttons on the notification balloon so the user can take direct action on the notification rather than having to take action through some other part of the application (a form or menu for example).

Was it helpful?

Solution

There's no built-in method for this. I would suggest writing your own "balloon" and activating that instead of calling .ShowBalloon()

OTHER TIPS

This is how I do it. It may not be the correct way of doing it. I do this way because .ShowBalloonTip(i) doesn't work as expected for me. It doesn't stay for i seconds and go off. So I do in another thread and forcefully dispose off.

    private static NotifyIcon _notifyIcon;

    //you can call this public function
    internal static void ShowBalloonTip(Icon icon)
    {
        BackgroundWorker worker = new BackgroundWorker();
        worker.DoWork += new DoWorkEventHandler(worker_DoWork);
        worker.RunWorkerAsync(icon);
    }

    private static void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        Show(e);
        Thread.Sleep(2000); //meaning it displays for 2 seconds
        DisposeOff();
    }

    private static void Show(DoWorkEventArgs e)
    {
        _notifyIcon = new NotifyIcon();
        _notifyIcon.Icon = (Icon)e.Argument;

         _notifyIcon.BalloonTipTitle = "Environment file is opened";
        _notifyIcon.BalloonTipText = "Press alt+tab to switch between environment files";

        _notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
        _notifyIcon.Visible = true;
        _notifyIcon.ShowBalloonTip(2000); //sadly doesnt work for me :(
    }

    private static void DisposeOff()
    {
        if (_notifyIcon == null)
            return;

        _notifyIcon.Dispose();
        _notifyIcon = null;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top