Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add toast style popup to my application?

Tags:

c#

winforms

I have created an application that runs in the taskbar. When a user clicks the application it pops up etc. What I would like is similar functionality to that in MSN when one of my friends logs in. Apparently this is know as a toast popup? I basically want something to popup from every 20 minutes toast style fom the application in the taskbar.

My existing application is winforms based written in C# with .net 3.5

like image 416
anonym0use Avatar asked Jan 20 '09 12:01

anonym0use


People also ask

How do I make toast notifications?

Instantiate a Toast objectUse the makeText() method, which takes the following parameters: The application Context . The text that should appear to the user. The duration that the toast should remain on the screen.

How do I show toast notifications in Winforms app?

Start screen application shortcuts are in the %AppData%\Microsoft\Windows\Start Menu\Programs folder, and you need to add a shortcut to this folder to show toast notifications.

Where do you put toast notifications?

Follow these placement guidelines for Toast Notifications: Place them either top-center or top-right of the screen. If badging is being used, toasts should be placed underneath it. Note that top-right placements may negatively affect those using screen magnifiers.


3 Answers

For Customizable and Better looking notifications..

Check this link..

  • Windows Toast Notifications - GitHub
like image 146
Shark01 Avatar answered Oct 18 '22 16:10

Shark01


This is pretty simple. You just need to set window in off-screen area and animate it's position until it is fully visible. Here is a sample code:

public partial class Form1 : Form
{
    private Timer timer;
    private int startPosX;
    private int startPosY;

    public Form1()
    {
        InitializeComponent();
        // We want our window to be the top most
        TopMost = true;
        // Pop doesn't need to be shown in task bar
        ShowInTaskbar = false;
        // Create and run timer for animation
        timer = new Timer();
        timer.Interval = 50;
        timer.Tick += timer_Tick;
    }

    protected override void OnLoad(EventArgs e)
    {
        // Move window out of screen
        startPosX = Screen.PrimaryScreen.WorkingArea.Width - Width;
        startPosY = Screen.PrimaryScreen.WorkingArea.Height;
        SetDesktopLocation(startPosX, startPosY);
        base.OnLoad(e);
        // Begin animation
        timer.Start();
    }

    void timer_Tick(object sender, EventArgs e)
    {
        //Lift window by 5 pixels
        startPosY -= 5; 
        //If window is fully visible stop the timer
        if (startPosY < Screen.PrimaryScreen.WorkingArea.Height - Height)
            timer.Stop();
        else
           SetDesktopLocation(startPosX, startPosY);
    }
}
like image 45
aku Avatar answered Oct 18 '22 15:10

aku


There's support for notification balloons in Win32 (I'm not a .net programmer), with some useful properties as old new thing explains.

There's also a system wide semaphor which you should lock to prevent more than one popup from any application appearing at once.

There's a a couple of pages on the toast semaphor on msdn - the toast semaphor and in the broader context of usability. I also came across some example code to use the balloon api from C# while looking, but can't vouch for it.

like image 4
Pete Kirkham Avatar answered Oct 18 '22 16:10

Pete Kirkham