我创建了一个在任务栏中运行的应用程序。当用户单击该应用程序时,它会弹出等等。我想要的是与我的一个 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/