C# & WPF - Problem with taskbar popup notifier window
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();
}
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.
精彩评论