如何在我的应用程序中添加toast样式弹出窗口?

时间:2009-01-20 12:54:05

标签: c# winforms

我创建了一个在任务栏中运行的应用程序。当用户点击应用程序时,它会弹出等等。当我的一个朋友登录时,我想要的功能与MSN中的功能类似。显然这是一个知道的吐司弹出窗口? 我基本上希望从任务栏中的应用程序每隔20分钟吐出一些东西。

我现有的应用程序是基于C#和.net 3.5

编写的winforms

5 个答案:

答案 0 :(得分:23)

这很简单。您只需在屏幕外区域设置窗口并为其位置设置动画,直到它完全可见。以下是示例代码:

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);
    }
}

答案 1 :(得分:4)

Win32中支持通知气球(我不是.net程序员),有一些有用的属性old new thing explains

还有一个系统范围的信号量,你应该锁定它以防止同时出现的任何应用程序出现多个弹出窗口。

在msdn - the toast semaphorbroader context of usability上的吐司信号上有几页。我也遇到了一些example code使用来自C#的气球api,但不能担保它。

答案 2 :(得分:2)

答案 3 :(得分:0)

对于可自定义和更好看的通知..

检查此链接..

答案 4 :(得分:-1)

您正在将表单移出屏幕右侧,然后将其抬起。它实际上永远不会进入桌面视图。 X轴为左右,Y轴为上下。添加到X轴使其向右移动,并且添加到Y轴使其进一步向下。