我的应用程序的吐司风格弹出窗口

ano*_*use 10 c# winforms

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

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

干杯

aku*_*aku 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这没有考虑几个因素:*任务栏可以附加到屏幕的任何边缘;*用户可以在右边有一个辅助显示器(导致你的弹出窗口在任务栏附近弹出.我知道这是一个旧线程,但我想提到它给其他任何人看,就像我一样. (5认同)
  • 除了我上面的评论:即使看起来像二级屏幕不应该是一个问题(因为Screen.PrimaryScreen使用),Win7允许非主屏幕包含任务栏; 当然,任务栏位置仍然可以是屏幕的任何边缘.请参阅[此问题](http://stackoverflow.com/questions/1265379/how-to-find-windows-taskbar-location-and-size)以获取为任务栏找到正确边缘的答案. (3认同)