我设法创建了一个任务栏弹出窗口,就像使用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();
}
当你在它的时候,一定要考虑到不同的任务栏位置和屏幕。我怀疑你最近的代码可能会对最后一个代码有一些意想不到的效果。就我个人而言,如果我的任务栏位于左侧,右下方消失,我会发现它有点烦人。我希望它在左边,然后消失在左边。 – Stigma 2011-01-22 15:01:05