C# & WPF - 任务栏弹出通知窗口的问题

发布于 2024-10-13 16:08:42 字数 1639 浏览 6 评论 0原文

我成功地创建了一个任务栏弹出窗口,就像Messenger中的那样。 问题是,当它向下移动而不是消失在任务栏后面时,它只是移到任务栏后面。

如何让它消失在任务栏后面?不要忘记在 Windows 7 中任务栏是透明的!

这是我的代码:

public partial class WindowNotifier : Window
{
    double xPos = 0;
    double yPos = 0;
    Timer closeTimer;


    public WindowNotifier()
    {
        InitializeComponent();
        closeTimer = new Timer();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        SetValues();
        closeTimer.Tick+=new EventHandler(closeTimer_Tick);
        closeTimer.Start();
    }

    private void SetValues()
    {

        xPos = System.Windows.SystemParameters.WorkArea.Width;
        yPos = System.Windows.SystemParameters.WorkArea.Height;

        this.Left = xPos - this.Width;
        this.Top = yPos - this.Height;       

    }

    private void closeTimer_Tick(object sender, EventArgs e)
    {
        closeTimer.Interval = 50;
        double curYPos = this.Top;
        if (curYPos < yPos)
        {
            this.Top = curYPos + 8;

            this.Opacity = this.Opacity - 0.050;
        }
        else
        {
            this.Close();
        }
    }    
}

编辑: 我更改了计时器部分,因此现在我降低了控件的高度并重新定位了它。 现在的问题是它会闪烁。我该如何解决?

这是代码:

    closeTimer.Interval = 50;
    double curYPos = this.Top;
    int decAmount = 8;

    if(this.Height - decAmount > 0)
    {
        this.Height = this.Height - decAmount;
        this.Top = this.Top + decAmount;

        this.Opacity = this.Opacity - 0.010;
    }
    else
    {
        this.Height = 0;
        this.Close();
        closeTimer.Stop();
    }

I managed to create a task-bar pop-up window like the one in messenger.
The problem that when it moves down instead of disappear behind the task-bar it just goes behind it.

How can I make it disappear behind the task-bar? don't forget in windows 7 that task-bar is transparent!

Here is my code:

public partial class WindowNotifier : Window
{
    double xPos = 0;
    double yPos = 0;
    Timer closeTimer;


    public WindowNotifier()
    {
        InitializeComponent();
        closeTimer = new Timer();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        SetValues();
        closeTimer.Tick+=new EventHandler(closeTimer_Tick);
        closeTimer.Start();
    }

    private void SetValues()
    {

        xPos = System.Windows.SystemParameters.WorkArea.Width;
        yPos = System.Windows.SystemParameters.WorkArea.Height;

        this.Left = xPos - this.Width;
        this.Top = yPos - this.Height;       

    }

    private void closeTimer_Tick(object sender, EventArgs e)
    {
        closeTimer.Interval = 50;
        double curYPos = this.Top;
        if (curYPos < yPos)
        {
            this.Top = curYPos + 8;

            this.Opacity = this.Opacity - 0.050;
        }
        else
        {
            this.Close();
        }
    }    
}

EDIT:
I changed the timer part so now I decrease the height of the control and relocate it.
Now the problem is that it blinks. How can I solve it?

Here is the code:

    closeTimer.Interval = 50;
    double curYPos = this.Top;
    int decAmount = 8;

    if(this.Height - decAmount > 0)
    {
        this.Height = this.Height - decAmount;
        this.Top = this.Top + decAmount;

        this.Opacity = this.Opacity - 0.010;
    }
    else
    {
        this.Height = 0;
        this.Close();
        closeTimer.Stop();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

机场等船 2024-10-20 16:08:42

难道你不能不移动它,而是降低高度并同时向下移动相同的量吗?

尝试 SuspendLayout() 和 ResumeLayout() 来防止闪烁。我不太确定这会解决闪烁问题,但当有很多子控件时,它可能会挽救这一天。

您还可以尝试改变调整大小的时间间隔或将代码移至重绘/绘制事件。

除了调整大小之外,您还可以尝试剪切区域。

Couldn't you, instead of moving it, decrease the height and move it down at the same time by the same amount?

Try SuspendLayout() and ResumeLayout() to prevent flickering. I am not quite sure this will solve the flickering but when there are many child controls it might save the day.

You can also try to variate the interval at which you are resizing or move the code to the Redraw/Paint event.

Instead of resizing you could also try a Clipping Region.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文