2011-01-22 40 views
1

我设法创建了一个任务栏弹出窗口,就像使用Messenger的窗口一样。 问题是,当它向下移动而不是消失在任务栏后面时,它就会落在它后面。C#&WPF - 任务栏弹出通知窗口问题

如何让它消失在任务栏后面?不要忘记在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(); 
    } 
+1

当你在它的时候,一定要考虑到不同的任务栏位置和屏幕。我怀疑你最近的代码可能会对最后一个代码有一些意想不到的效果。就我个人而言,如果我的任务栏位于左侧,右下方消失,我会发现它有点烦人。我希望它在左边,然后消失在左边。 – Stigma 2011-01-22 15:01:05

回答

2

你能不能,而不是移动它,降低高度和相同的量其向下移动在同一时间?

尝试使用SuspendLayout()和ResumeLayout()来防止闪烁。我不太确定这会解决闪烁现象,但是当有许多子控件时,它可能会节省一天的时间。

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

而不是调整大小,你也可以尝试一个剪切区域。

+0

天才!现在窗口闪烁的问题。 – 2011-01-22 14:43:40