C# 如何向我的应用程序添加吐司样式弹出窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/461184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 04:17:49  来源:igfitidea点击:

How to add toast style popup to my application?

c#winforms

提问by anonym0use

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.

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

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

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

采纳答案by aku

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

回答by Pete Kirkham

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 a a couple of pages on the toast semaphor on msdn - the toast semaphorand in the broader context of usability. I also came across some example codeto use the balloon api from C# while looking, but can't vouch for it.

msdn 上有几页关于 toast semaphor 的页面 - toast semaphor更广泛的可用性上下文。我还遇到了一些示例代码,在查找时使用 C# 中的气球 api,但无法保证。

回答by afollestad

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.

您将窗体从屏幕向右移出,然后将其抬起。它永远不会真正升入桌面视图。X 轴为左右,Y 轴为上下。添加到 X 轴使其进一步向右,添加到 Y 轴使其进一步向下。

回答by Shark01

For Customizable and Better looking notifications..

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

Check this link..

检查这个链接..