简体   繁体   English

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

[英]How to add toast style popup to my application?

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? 当用户点击应用程序时,它会弹出等等。当我的一个朋友登录时,我想要的功能与MSN中的功能类似。显然这是一个知道的吐司弹出窗口? I basically want something to popup from every 20 minutes toast style fom the application in the taskbar. 我基本上希望从任务栏中的应用程序每隔20分钟弹出一些东西。

My existing application is winforms based written in C# with .net 3.5 我现有的应用程序是基于C#和.net 3.5编写的winforms

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

There's support for notification balloons in Win32 (I'm not a .net programmer), with some useful properties as old new thing explains . 在Win32中支持通知气球(我不是.net程序员),有一些有用的属性,如旧的新东西所解释的那样

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 aa couple of pages on the toast semaphor on msdn - the toast semaphor and in the broader context of usability . 在msdn上的吐司信号上有几页 - 吐司信号更广泛的可用性 I also came across some example code to use the balloon api from C# while looking, but can't vouch for it. 我还看到了一些示例代码 ,在查看时使用C#的气球api,但无法保证它。

For Customizable and Better looking notifications.. 对于可定制和更好看的通知..

Check this link.. 检查此链接..

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. X轴为左右,Y轴为上下。 Adding to the X-axis makes it go further right, and adding to the Y-axis makes it go further down. 添加到X轴使其更加正确,并且添加到Y轴使其进一步向下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM