Closing animation changes

This commit is contained in:
Jaex 2013-12-30 09:46:50 +02:00
parent 13206ac96d
commit 0d44f24b8e
2 changed files with 24 additions and 11 deletions

View file

@ -51,7 +51,7 @@ private void InitializeComponent()
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(300, 150);
this.ClientSize = new System.Drawing.Size(400, 300);
this.Cursor = System.Windows.Forms.Cursors.Hand;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "NotificationForm";

View file

@ -42,11 +42,14 @@ public partial class NotificationForm : Form
{
public Image ToastImage { get; private set; }
public string ToastText { get; private set; }
public string URL { get; private set; }
public string ToastURL { get; private set; }
private int windowOffset = 3;
private bool mouseInside = false;
private bool durationEnd = false;
private bool closingAnimation = true;
private int closingAnimationDuration = 2000;
private int closingAnimationInterval = 50;
public NotificationForm(int duration, Size size, Image img, string url)
{
@ -55,7 +58,7 @@ public NotificationForm(int duration, Size size, Image img, string url)
img = ImageHelpers.ResizeImageLimit(img, size);
img = ImageHelpers.DrawCheckers(img);
ToastImage = img;
URL = url;
ToastURL = url;
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
Size = new Size(img.Width + 2, img.Height + 2);
@ -78,19 +81,29 @@ private void tDuration_Tick(object sender, EventArgs e)
private void StartClosing()
{
Opacity = 1;
tOpacity.Start();
if (closingAnimation)
{
Opacity = 1;
tOpacity.Interval = closingAnimationInterval;
tOpacity.Start();
}
else
{
Close();
}
}
private void tOpacity_Tick(object sender, EventArgs e)
{
if (Opacity <= 0.05f)
float opacityDecrement = (float)closingAnimationInterval / closingAnimationDuration;
if (Opacity > opacityDecrement)
{
Close();
Opacity -= opacityDecrement;
}
else
{
Opacity -= 0.05f;
Close();
}
}
@ -139,9 +152,9 @@ private void NotificationForm_MouseClick(object sender, MouseEventArgs e)
{
tDuration.Stop();
if (e.Button == MouseButtons.Left && !string.IsNullOrEmpty(URL))
if (e.Button == MouseButtons.Left && !string.IsNullOrEmpty(ToastURL))
{
Helpers.LoadBrowserAsync(URL);
Helpers.LoadBrowserAsync(ToastURL);
}
Close();
@ -154,7 +167,7 @@ private void NotificationForm_MouseEnter(object sender, EventArgs e)
tOpacity.Stop();
Opacity = 1;
ToastText = URL;
ToastText = ToastURL;
Refresh();
}