12

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

LarsTech
  • 80,625
  • 14
  • 153
  • 225
anonym0use
  • 2,936
  • 4
  • 25
  • 26

3 Answers3

25

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);
    }
}
aku
  • 122,288
  • 32
  • 173
  • 203
  • 5
    This doesn't account for several factors: * Taskbar could be attached to any edge of the screen; * User could have a secondary monitor on the right (causing your popup window to pop up nowhere near the taskbar. I know this is an old thread, but I wanted to mention it for anyone else looking, as I was. – Geoff Jun 27 '11 at 13:40
  • 4
    Addition to my above comment: Even though it looks like having a secondary screen shouldn't be an issue (because of the Screen.PrimaryScreen usage), Win7 allows non-primary screens to contain the taskbar; and of course, the taskbar location could still be any edge of the screen. See [this question](http://stackoverflow.com/questions/1265379/how-to-find-windows-taskbar-location-and-size) for an answer to finding the correct edge for the taskbar. – Geoff Jun 27 '11 at 13:50
4

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.

Pete Kirkham
  • 48,893
  • 5
  • 92
  • 171
-1

You're moving the form out of the screen to the right, and then raising it. It would never actually raise into the desktop view. X-axis is right and left, Y-axis is up and down. Adding to the X-axis makes it go further right, and adding to the Y-axis makes it go further down.

afollestad
  • 2,929
  • 5
  • 30
  • 44