Class TransDialog.cs
Class Notification.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace CSharpNetNotification
{
public class Notification : TransDialog
{
#region Ctor, init code and dispose
public Notification()
: base(true)
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion // Ctor and init code
#region Event handler
private void Notification_Load(object sender, System.EventArgs e)
{
int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
this.Left = screenWidth - this.Width;
this.Top = screenHeight - this.Height;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
this.Close();
}
private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
string link = e.Link.LinkData.ToString();
if (link != null && link.Length > 0)
System.Diagnostics.Process.Start(link);
}
#endregion // Event handler
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// timer1
//
this.timer1.Interval = 3000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// pictureBox1
//
this.pictureBox1.Image = global::CSharpNetNotification.Properties.Resources.welcome;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(492, 181);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Notification
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(489, 180);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "Notification";
this.Text = "Notification";
this.TopMost = true;
this.Load += new System.EventHandler(this.Notification_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region Designer generated variables
private System.Windows.Forms.Timer timer1;
private PictureBox pictureBox1;
private System.ComponentModel.IContainer components;
#endregion
}
}
Code source par ici: CSharp.NETNotification
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CSharpNetNotification
{
/// <summary>
/// Base class that gives any form that derives from it the effect of slowly
/// appearing and then disapperaing. Much like outlook email notification pop-ups
/// </summary>
public class TransDialog : System.Windows.Forms.Form
{
#region Constructor
public TransDialog()
{
InitializeComponents();
}
public TransDialog(bool disposeAtEnd)
{
m_bDisposeAtEnd = disposeAtEnd;
InitializeComponents();
}
void InitializeComponents()
{
this.components = new System.ComponentModel.Container();
this.m_clock = new Timer(this.components);
this.m_clock.Interval = 100;
this.SuspendLayout();
//m_clock
this.m_clock.Tick += new EventHandler(Animate);
//TransDialog
this.Load += new EventHandler(TransDialog_Load);
this.Closing += new CancelEventHandler(TransDialog_Closing);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
#region Event handlers
private void TransDialog_Load(object sender, EventArgs e)
{
this.Opacity = 0.0;
m_bShowing = true;
m_clock.Start();
}
private void TransDialog_Closing(object sender, CancelEventArgs e)
{
if (!m_bForceClose)
{
m_origDialogResult = this.DialogResult;
e.Cancel = true;
m_bShowing = false;
m_clock.Start();
}
else
{
this.DialogResult = m_origDialogResult;
}
}
#endregion
#region Private methods
private void Animate(object sender, EventArgs e)
{
if (m_bShowing)
{
if (this.Opacity < 1)
{
this.Opacity += 0.1;
}
else
{
m_clock.Stop();
}
}
else
{
if (this.Opacity > 0)
{
this.Opacity -= 0.1;
}
else
{
m_clock.Stop();
m_bForceClose = true;
this.Close();
if (m_bDisposeAtEnd)
this.Dispose();
}
}
}
#endregion
#region overrides
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
#region private variables
private System.ComponentModel.IContainer components = null;
private Timer m_clock;
private bool m_bShowing = true;
private bool m_bForceClose = false;
private DialogResult m_origDialogResult;
private bool m_bDisposeAtEnd = false;
#endregion // private variables
}
}
Class Notification.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace CSharpNetNotification
{
public class Notification : TransDialog
{
#region Ctor, init code and dispose
public Notification()
: base(true)
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion // Ctor and init code
#region Event handler
private void Notification_Load(object sender, System.EventArgs e)
{
int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
this.Left = screenWidth - this.Width;
this.Top = screenHeight - this.Height;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
this.Close();
}
private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
string link = e.Link.LinkData.ToString();
if (link != null && link.Length > 0)
System.Diagnostics.Process.Start(link);
}
#endregion // Event handler
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// timer1
//
this.timer1.Interval = 3000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// pictureBox1
//
this.pictureBox1.Image = global::CSharpNetNotification.Properties.Resources.welcome;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(492, 181);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Notification
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(489, 180);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "Notification";
this.Text = "Notification";
this.TopMost = true;
this.Load += new System.EventHandler(this.Notification_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region Designer generated variables
private System.Windows.Forms.Timer timer1;
private PictureBox pictureBox1;
private System.ComponentModel.IContainer components;
#endregion
}
}
Code source par ici: CSharp.NETNotification
