我设法创建了一个类似于 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();
}