c# - 如何向我的应用程序添加 toast 样式弹出窗口?

标签 c# winforms

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

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

最佳答案

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

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

关于c# - 如何向我的应用程序添加 toast 样式弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/461184/

相关文章:

c# - 在运行时定位 Windows 窗体上的 ErrorProvider

c# - 刷新其中的数据时,是否必须从列表框中删除 selectedIndexChange 事件?

c# - 使用C#在Windows 7中模拟鼠标点击和鼠标移动

c# - 估计 GUID 中数字出现的概率

c# - 如何访问新资源(图像)以设置为背景

c# - Application.EnableVisualStyles() 有什么作用吗?

c# - 转换为基类,并调用其虚方法导致计算器异常

c# - 以 Windows XP 为目标平台的 VS 2015 中推荐的内容

C# 需要一个以两个 0 开头的六位数字

c# - 尽管有有效的 Token,为什么我仍会收到未授权的信息?