Please find below my contribution to this Project
I've added the following features:
New properties: AppearBySliding, Padding, ContentTextAlignementToast collection (that manages displaying several -stacked- 'Toasts' in the same time.) The ToastCollection declaration has been append after the TaskbarNotifier class and should be used as follow:
protected ToastCollection m_ColToast = new ToastCollection();
private TaskbarNotifier InitTaskBarNotifier(TaskbarNotifier notifier, Color titleColor)
{
notifier.Base = m_ColToast;
notifier.SetBackgroundBitmap(new Bitmap(GetType(), "Images.notifierLiveMessengerSkin.png"), Color.FromArgb(255, 0, 255));
notifier.SetCloseBitmap(new Bitmap(GetType(), "Images.notifierLiveMessengerClose.png"), Color.FromArgb(255, 0, 255), new Point(184, 9));
notifier.TitleRectangle = new Rectangle(10, 3, 180, 20);
notifier.ContentRectangle = new Rectangle(4, 28, 195, 84);
notifier.ContentTextAlignement = ContentAlignment.MiddleCenter;
notifier.NormalTitleColor = titleColor;
notifier.CloseClickable = true;
notifier.TitleClickable = false;
notifier.ContentClickable = false;
notifier.EnableSelectionRectangle = true;
notifier.KeepVisibleOnMousOver = true;
notifier.ReShowOnMouseOver = true;
notifier.Padding = 0;
notifier.AppearBySliding = false;
return notifier;
}
And each time you want to show a popup call the InitTaskBarNotifier method (see above), it will add the new toast to the Toast Collection.
...
TaskbarNotifier m_NotifierTmp = InitTaskBarNotifier(new TaskbarNotifier(), titleColor);
m_NotifierTmp.Show(title, content, appearingDuration, showingDuration, disappearingDuration);
...
Finally, below, there is the full updated class and the new ToastCollection class (sorry for size and format)
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace CustomUIControls
{
public class TaskbarNotifier : Form
{
#region TaskbarNotifier Protected Members
protected Bitmap BackgroundBitmap = null;
protected Bitmap CloseBitmap = null;
protected Point CloseBitmapLocation;
protected Size CloseBitmapSize;
protected Rectangle RealTitleRectangle;
protected Rectangle RealContentRectangle;
protected Rectangle WorkAreaRectangle;
protected Timer timer = new Timer();
protected TaskbarStates taskbarState = TaskbarStates.hidden;
protected string titleText;
protected string contentText;
protected Color normalTitleColor = Color.FromArgb(255, 255, 255);
protected Color hoverTitleColor = Color.FromArgb(255, 0, 0);
protected Color normalContentColor = Color.FromArgb(0, 0, 0);
protected Color hoverContentColor = Color.FromArgb(0, 0, 0x66);
protected Font normalTitleFont = new Font("Arial", 12, FontStyle.Regular | FontStyle.Bold, GraphicsUnit.Pixel);
protected Font hoverTitleFont = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Pixel);
protected Font normalContentFont = new Font("Arial", 11, FontStyle.Regular, GraphicsUnit.Pixel);
protected Font hoverContentFont = new Font("Arial", 11, FontStyle.Regular, GraphicsUnit.Pixel);
protected int nShowEvents;
protected int nHideEvents;
protected int nVisibleEvents;
protected int nIncrementShow;
protected int nIncrementHide;
protected bool bIsMouseOverPopup = false;
protected bool bIsMouseOverClose = false;
protected bool bIsMouseOverContent = false;
protected bool bIsMouseOverTitle = false;
protected bool bIsMouseDown = false;
protected bool bKeepVisibleOnMouseOver = true;
protected bool bReShowOnMouseOver = false;
protected bool bAppearBySliding = true;
protected int nPadding = 10;
protected int nBaseWindowBottom = 0;
protected int nBaseWindowRight = 0;
protected ToastCollection colBase = null;
protected bool bMoving = false;
protected int nMouseDownX;
protected int nMouseDownY;
protected ContentAlignment caContentAlignement;
#endregion
#region TaskbarNotifier Public Members
public Rectangle TitleRectangle;
public Rectangle ContentRectangle;
public bool TitleClickable = false;
public bool ContentClickable = true;
public bool CloseClickable = true;
public bool EnableSelectionRectangle = true;
public event EventHandler CloseClick = null;
public event EventHandler TitleClick = null;
public event EventHandler ContentClick = null;
#endregion
#region TaskbarNotifier Enums
public enum TaskbarStates
{
hidden = 0,
appearing = 1,
visible = 2,
disappearing = 3
}
#endregion
#region TaskbarNotifier Constructor
public TaskbarNotifier()
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Minimized;
base.Hide();
WindowState = FormWindowState.Normal;
ShowInTaskbar = false;
TopMost = true;
MaximizeBox = false;
MinimizeBox = false;
ControlBox = false;
timer.Enabled = true;
timer.Tick += new EventHandler(OnTimer);
}
#endregion
#region TaskbarNotifier Properties
public TaskbarStates TaskbarState
{
get
{
return taskbarState;
}
}
public string TitleText
{
get
{
return titleText;
}
set
{
titleText = value;
Refresh();
}
}
public string ContentText
{
get
{
return contentText;
}
set
{
contentText = value;
Refresh();
}
}
public Color NormalTitleColor
{
get
{
return normalTitleColor;
}
set
{
normalTitleColor = value;
Refresh();
}
}
public Color HoverTitleColor
{
get
{
return hoverTitleColor;
}
set
{
hoverTitleColor = value;
Refresh();
}
}
public Color NormalContentColor
{
get
{
return normalContentColor;
}
set
{
normalContentColor = value;
Refresh();
}
}
public Color HoverContentColor
{
get
{
return hoverContentColor;
}
set
{
hoverContentColor = value;
Refresh();
}
}
public Font NormalTitleFont
{
get
{
return normalTitleFont;
}
set
{
normalTitleFont = value;
Refresh();
}
}
public Font HoverTitleFont
{
get
{
return hoverTitleFont;
}
set
{
hoverTitleFont = value;
Refresh();
}
}
public Font NormalContentFont
{
get
{
return normalContentFont;
}
set
{
normalContentFont = value;
Refresh();
}
}
public Font HoverContentFont
{
get
{
return hoverContentFont;
}
set
{
hoverContentFont = value;
Refresh();
}
}
public bool KeepVisibleOnMousOver
{
get
{
return bKeepVisibleOnMouseOver;
}
set
{
bKeepVisibleOnMouseOver = value;
}
}
public bool ReShowOnMouseOver
{
get
{
return bReShowOnMouseOver;
}
set
{
bReShowOnMouseOver = value;
}
}
public bool AppearBySliding
{
get
{
return bAppearBySliding;
}
set
{
bAppearBySliding = value;
}
}
public new int Padding
{
get
{
return nPadding;
}
set
{
nPadding = value;
Refresh();
}
}
public int BaseWindowBottom
{
get
{
return nBaseWindowBottom;
}
set
{
nBaseWindowBottom = value;
Refresh();
}
}
public int BaseWindowRight
{
get
{
return nBaseWindowRight;
}
set
{
nBaseWindowRight = value;
Refresh();
}
}
public ToastCollection Base
{
get
{
return colBase;
}
set
{
colBase = value;
Refresh();
}
}
public ContentAlignment ContentTextAlignement
{
get
{
return caContentAlignement;
}
set
{
caContentAlignement = value;
Refresh();
}
}
#endregion
#region TaskbarNotifier Public Methods
[DllImport("user32.dll")]
private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
public void Show(string strTitle, string strContent, int nTimeToShow, int nTimeToStay, int nTimeToHide)
{
WorkAreaRectangle = Screen.GetWorkingArea(WorkAreaRectangle);
titleText = strTitle;
contentText = strContent;
nVisibleEvents = nTimeToStay;
CalculateMouseRectangles();
int nEvents = 0;
if (nTimeToShow > 10)
{
nEvents = Math.Min((nTimeToShow / 10), BackgroundBitmap.Height);
nShowEvents = nTimeToShow / nEvents;
nIncrementShow = BackgroundBitmap.Height / nEvents;
}
else
{
nShowEvents = 10;
nIncrementShow = BackgroundBitmap.Height;
}
if (nTimeToHide > 10)
{
nEvents = Math.Min((nTimeToHide / 10), BackgroundBitmap.Height);
nHideEvents = nTimeToHide / nEvents;
nIncrementHide = BackgroundBitmap.Height / nEvents;
}
else
{
nHideEvents = 10;
nIncrementHide = BackgroundBitmap.Height;
}
if (colBase != null)
colBase.AddToast(this, this.WorkAreaRectangle.Height,
ref nBaseWindowBottom, ref nBaseWindowRight);
switch (taskbarState)
{
case TaskbarStates.hidden:
taskbarState = TaskbarStates.appearing;
if (bAppearBySliding)
{
this.Opacity = 1.0;
SetBounds(WorkAreaRectangle.Right - BackgroundBitmap.Width - nPadding - nBaseWindowRight,
WorkAreaRectangle.Bottom,
BackgroundBitmap.Width, 0);
}
else
{
this.Opacity = 0.0;
SetBounds(WorkAreaRectangle.Right - BackgroundBitmap.Width - nPadding - nBaseWindowRight,
WorkAreaRectangle.Bottom - BackgroundBitmap.Height - nPadding - nBaseWindowBottom,
BackgroundBitmap.Width, BackgroundBitmap.Height);
}
timer.Interval = nShowEvents;
timer.Start();
ShowWindow(this.Handle, 4);
break;
case TaskbarStates.appearing:
Refresh();
break;
case TaskbarStates.visible:
timer.Stop();
timer.Interval = nVisibleEvents;
timer.Start();
Refresh();
break;
case TaskbarStates.disappearing:
timer.Stop();
taskbarState = TaskbarStates.visible;
if (bAppearBySliding)
{
SetBounds(WorkAreaRectangle.Right - BackgroundBitmap.Width - nPadding - nBaseWindowRight,
WorkAreaRectangle.Bottom - BackgroundBitmap.Height - nPadding - nBaseWindowBottom,
BackgroundBitmap.Width, BackgroundBitmap.Height);
}
else
{
SetBounds(WorkAreaRectangle.Right - BackgroundBitmap.Width - nPadding - nBaseWindowRight,
WorkAreaRectangle.Bottom - nPadding - nBaseWindowBottom,
BackgroundBitmap.Width, 0);
}
timer.Interval = nVisibleEvents;
timer.Start();
Refresh();
break;
}
}
public new void Hide()
{
if (taskbarState != TaskbarStates.hidden)
{
timer.Stop();
taskbarState = TaskbarStates.hidden;
base.Hide();
if (colBase != null)
colBase.KillWindow(this);
}
}
public void SetBackgroundBitmap(string strFilename, Color transparencyColor)
{
BackgroundBitmap = new Bitmap(strFilename);
Width = BackgroundBitmap.Width;
Height = BackgroundBitmap.Height;
Region = BitmapToRegion(BackgroundBitmap, transparencyColor);
}
public void SetBackgroundBitmap(Image image, Color transparencyColor)
{
BackgroundBitmap = new Bitmap(image);
Width = BackgroundBitmap.Width;
Height = BackgroundBitmap.Height;
Region = BitmapToRegion(BackgroundBitmap, transparencyColor);
}
public void SetCloseBitmap(string strFilename, Color transparencyColor, Point position)
{
CloseBitmap = new Bitmap(strFilename);
CloseBitmap.MakeTransparent(transparencyColor);
CloseBitmapSize = new Size(CloseBitmap.Width / 3, CloseBitmap.Height);
CloseBitmapLocation = position;
}
public void SetCloseBitmap(Image image, Color transparencyColor, Point position)
{
CloseBitmap = new Bitmap(image);
CloseBitmap.MakeTransparent(transparencyColor);
CloseBitmapSize = new Size(CloseBitmap.Width / 3, CloseBitmap.Height);
CloseBitmapLocation = position;
}
#endregion
#region TaskbarNotifier Protected Methods
protected void DrawCloseButton(Graphics grfx)
{
if (CloseBitmap != null)
{
Rectangle rectDest = new Rectangle(CloseBitmapLocation, CloseBitmapSize);
Rectangle rectSrc;
if (bIsMouseOverClose)
{
if (bIsMouseDown)
rectSrc = new Rectangle(new Point(CloseBitmapSize.Width * 2, 0), CloseBitmapSize);
else
rectSrc = new Rectangle(new Point(CloseBitmapSize.Width, 0), CloseBitmapSize);
}
else
rectSrc = new Rectangle(new Point(0, 0), CloseBitmapSize);
grfx.DrawImage(CloseBitmap, rectDest, rectSrc, GraphicsUnit.Pixel);
}
}
protected void DrawText(Graphics grfx)
{
if (titleText != null && titleText.Length != 0)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Center;
sf.FormatFlags = StringFormatFlags.NoWrap;
sf.Trimming = StringTrimming.EllipsisCharacter;
if (bIsMouseOverTitle)
grfx.DrawString(titleText, hoverTitleFont, new SolidBrush(hoverTitleColor), TitleRectangle, sf);
else
grfx.DrawString(titleText, normalTitleFont, new SolidBrush(normalTitleColor), TitleRectangle, sf);
}
if (contentText != null && contentText.Length != 0)
{
StringFormat sf = new StringFormat();
switch (caContentAlignement)
{
case ContentAlignment.BottomCenter:
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Far;
break;
case ContentAlignment.BottomLeft:
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Far;
break;
case ContentAlignment.BottomRight:
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Far;
break;
case ContentAlignment.MiddleCenter:
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.MiddleLeft:
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.MiddleRight:
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.TopCenter:
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Near;
break;
case ContentAlignment.TopLeft:
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Near;
break;
case ContentAlignment.TopRight:
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Near;
break;
default:
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
break;
}
sf.FormatFlags = StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.LineLimit;
sf.Trimming = StringTrimming.EllipsisWord;
if (bIsMouseOverContent)
{
grfx.DrawString(contentText, hoverContentFont, new SolidBrush(hoverContentColor), ContentRectangle, sf);
if (EnableSelectionRectangle)
ControlPaint.DrawBorder3D(grfx, RealContentRectangle, Border3DStyle.Etched,
Border3DSide.Top | Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right);
}
else
grfx.DrawString(contentText, normalContentFont, new SolidBrush(normalContentColor), ContentRectangle, sf);
}
}
protected void CalculateMouseRectangles()
{
Graphics grfx = CreateGraphics();
StringFormat sf = new StringFormat();
switch (caContentAlignement)
{
case ContentAlignment.BottomCenter:
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Far;
break;
case ContentAlignment.BottomLeft:
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Far;
break;
case ContentAlignment.BottomRight:
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Far;
break;
case ContentAlignment.MiddleCenter:
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.MiddleLeft:
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.MiddleRight:
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.TopCenter:
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Near;
break;
case ContentAlignment.TopLeft:
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Near;
break;
case ContentAlignment.TopRight:
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Near;
break;
default:
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
break;
}
sf.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
SizeF sizefTitle = grfx.MeasureString(titleText, hoverTitleFont, TitleRectangle.Width, sf);
SizeF sizefContent = grfx.MeasureString(contentText, hoverContentFont, ContentRectangle.Width, sf);
grfx.Dispose();
if (sizefTitle.Height > TitleRectangle.Height)
{
RealTitleRectangle = new Rectangle(TitleRectangle.Left, TitleRectangle.Top,
TitleRectangle.Width, TitleRectangle.Height);
}
else
{
RealTitleRectangle = new Rectangle(TitleRectangle.Left, TitleRectangle.Top,
(int)sizefTitle.Width, (int)sizefTitle.Height);
}
RealTitleRectangle.Inflate(0, 2);
int RealHeight = (sizefContent.Height > ContentRectangle.Height) ? ContentRectangle.Height : (int)sizefContent.Height;
switch (caContentAlignement)
{
case ContentAlignment.BottomCenter:
RealContentRectangle = new Rectangle((ContentRectangle.Width - (int)sizefContent.Width) / 2 + ContentRectangle.Left,
(ContentRectangle.Height - RealHeight) + ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
case ContentAlignment.BottomLeft:
RealContentRectangle = new Rectangle(ContentRectangle.Left,
(ContentRectangle.Height - RealHeight) + ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
case ContentAlignment.BottomRight:
RealContentRectangle = new Rectangle((ContentRectangle.Width - (int)sizefContent.Width) + ContentRectangle.Left,
(ContentRectangle.Height - RealHeight) + ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
case ContentAlignment.MiddleCenter:
RealContentRectangle = new Rectangle((ContentRectangle.Width - (int)sizefContent.Width) / 2 + ContentRectangle.Left,
(ContentRectangle.Height - RealHeight) / 2 + ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
case ContentAlignment.MiddleLeft:
RealContentRectangle = new Rectangle(ContentRectangle.Left,
(ContentRectangle.Height - RealHeight) / 2 + ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
case ContentAlignment.MiddleRight:
RealContentRectangle = new Rectangle((ContentRectangle.Width - (int)sizefContent.Width) + ContentRectangle.Left,
(ContentRectangle.Height - RealHeight) / 2 + ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
case ContentAlignment.TopCenter:
RealContentRectangle = new Rectangle((ContentRectangle.Width - (int)sizefContent.Width) / 2 + ContentRectangle.Left,
ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
case ContentAlignment.TopLeft:
RealContentRectangle = new Rectangle(ContentRectangle.Left,
ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
case ContentAlignment.TopRight:
RealContentRectangle = new Rectangle((ContentRectangle.Width - (int)sizefContent.Width) + ContentRectangle.Left,
ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
default:
RealContentRectangle = new Rectangle((ContentRectangle.Width - (int)sizefContent.Width) / 2 + ContentRectangle.Left,
(ContentRectangle.Height - RealHeight) / 2 + ContentRectangle.Top,
(int)sizefContent.Width, RealHeight);
break;
}
RealContentRectangle.Inflate(4, 2);
}
protected Region BitmapToRegion(Bitmap bitmap, Color transparencyColor)
{
if (bitmap == null)
throw new ArgumentNullException("Bitmap", "Bitmap cannot be null!");
int height = bitmap.Height;
int width = bitmap.Width;
GraphicsPath path = new GraphicsPath();
for (int j = 0; j < height; j++)
for (int i = 0; i < width; i++)
{
if (bitmap.GetPixel(i, j) == transparencyColor)
continue;
int x0 = i;
while ((i < width) && (bitmap.GetPixel(i, j) != transparencyColor))
i++;
path.AddRectangle(new Rectangle(x0, j, i - x0, 1));
}
Region region = new Region(path);
path.Dispose();
return region;
}
#endregion
#region TaskbarNotifier Events Overrides
private void OnTimer(Object obj, EventArgs ea)
{
switch (taskbarState)
{
case TaskbarStates.appearing:
if (bAppearBySliding)
{
if (Height < BackgroundBitmap.Height)
SetBounds(Left, Top - nIncrementShow, Width, Height + nIncrementShow);
else
{
if (Bottom > WorkAreaRectangle.Bottom - nPadding - nBaseWindowBottom)
SetBounds(Left, Top - nIncrementShow, Width, Height);
else
{
timer.Stop();
Height = BackgroundBitmap.Height;
timer.Interval = nVisibleEvents;
taskbarState = TaskbarStates.visible;
timer.Start();
}
}
}
else
{
if (Opacity < 1.0)
Opacity = Opacity + (1.0 / (BackgroundBitmap.Height / nIncrementShow));
else
{
timer.Stop();
Height = BackgroundBitmap.Height;
timer.Interval = nVisibleEvents;
taskbarState = TaskbarStates.visible;
timer.Start();
}
}
break;
case TaskbarStates.visible:
timer.Stop();
timer.Interval = nHideEvents;
if ((bKeepVisibleOnMouseOver && !bIsMouseOverPopup) || (!bKeepVisibleOnMouseOver))
{
taskbarState = TaskbarStates.disappearing;
}
timer.Start();
break;
case TaskbarStates.disappearing:
if (bReShowOnMouseOver && bIsMouseOverPopup)
{
taskbarState = TaskbarStates.appearing;
}
else
{
if (bAppearBySliding)
{
if ((Top + Height) < WorkAreaRectangle.Bottom)
SetBounds(Left, Top + nIncrementHide, Width, Height);
else
if (Top < WorkAreaRectangle.Bottom)
SetBounds(Left, Top + nIncrementHide, Width, Height - nIncrementHide);
else
Hide();
}
else
{
if (Opacity > 0.1)
Opacity = Opacity - (1.0 / (BackgroundBitmap.Height / nIncrementHide));
else
Hide();
}
}
break;
}
}
protected override void OnMouseEnter(EventArgs ea)
{
base.OnMouseEnter(ea);
bIsMouseOverPopup = true;
Refresh();
}
protected override void OnMouseLeave(EventArgs ea)
{
base.OnMouseLeave(ea);
bIsMouseOverPopup = false;
bIsMouseOverClose = false;
bIsMouseOverTitle = false;
bIsMouseOverContent = false;
Refresh();
}
protected override void OnMouseMove(MouseEventArgs mea)
{
base.OnMouseMove(mea);
if (bMoving)
{
Point temp = new Point(0, 0);
temp.X = Location.X + (mea.X - nMouseDownX);
temp.Y = Location.Y + (mea.Y - nMouseDownY);
if ((temp.X + this.Size.Width) > Screen.GetWorkingArea(this.WorkAreaRectangle).Width)
temp.X = Screen.GetWorkingArea(this.WorkAreaRectangle).Width - this.Size.Width;
if ((temp.Y + this.Size.Height) > Screen.GetWorkingArea(this.WorkAreaRectangle).Height)
temp.Y = Screen.GetWorkingArea(this.WorkAreaRectangle).Height - this.Size.Height;
if (temp.X < 0)
temp.X = 0;
if (temp.Y < 0)
temp.Y = 0;
Location = temp;
Application.UserAppDataRegistry.SetValue("ToastBottom", WorkAreaRectangle.Height - Top - Height - Padding);
Application.UserAppDataRegistry.SetValue("ToastRight", WorkAreaRectangle.Width - Left - Width - Padding);
nBaseWindowBottom = WorkAreaRectangle.Height - Top - Height - Padding;
nBaseWindowRight = WorkAreaRectangle.Width - Left - Width - Padding;
}
bool bContentModified = false;
if ((mea.X > CloseBitmapLocation.X)
&& (mea.X < CloseBitmapLocation.X + CloseBitmapSize.Width)
&& (mea.Y > CloseBitmapLocation.Y)
&& (mea.Y < CloseBitmapLocation.Y + CloseBitmapSize.Height)
&& CloseClickable)
{
if (!bIsMouseOverClose)
{
bIsMouseOverClose = true;
bIsMouseOverTitle = false;
bIsMouseOverContent = false;
Cursor = Cursors.Hand;
bContentModified = true;
}
}
else if (RealContentRectangle.Contains(new Point(mea.X, mea.Y)) && ContentClickable)
{
if (!bIsMouseOverContent)
{
bIsMouseOverClose = false;
bIsMouseOverTitle = false;
bIsMouseOverContent = true;
Cursor = Cursors.Hand;
bContentModified = true;
}
}
else if (RealTitleRectangle.Contains(new Point(mea.X, mea.Y)) && TitleClickable)
{
if (!bIsMouseOverTitle)
{
bIsMouseOverClose = false;
bIsMouseOverTitle = true;
bIsMouseOverContent = false;
Cursor = Cursors.Hand;
bContentModified = true;
}
}
else
{
if (bIsMouseOverClose || bIsMouseOverTitle || bIsMouseOverContent)
bContentModified = true;
bIsMouseOverClose = false;
bIsMouseOverTitle = false;
bIsMouseOverContent = false;
Cursor = Cursors.Default;
}
if (bContentModified)
Refresh();
}
protected override void OnMouseDown(MouseEventArgs mea)
{
base.OnMouseDown(mea);
bIsMouseDown = true;
if (bIsMouseOverClose)
Refresh();
else
if (mea.Button == MouseButtons.Left)
{
bMoving = true;
nMouseDownX = mea.X;
nMouseDownY = mea.Y;
}
}
protected override void OnMouseUp(MouseEventArgs mea)
{
base.OnMouseUp(mea);
bIsMouseDown = false;
if (mea.Button == MouseButtons.Left)
bMoving = false;
if (bIsMouseOverClose)
{
Hide();
if (CloseClick != null)
CloseClick(this, new EventArgs());
}
else if (bIsMouseOverTitle)
{
if (TitleClick != null)
TitleClick(this, new EventArgs());
}
else if (bIsMouseOverContent)
{
if (ContentClick != null)
ContentClick(this, new EventArgs());
}
}
protected override void OnPaintBackground(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
grfx.PageUnit = GraphicsUnit.Pixel;
Graphics offScreenGraphics;
Bitmap offscreenBitmap;
offscreenBitmap = new Bitmap(BackgroundBitmap.Width, BackgroundBitmap.Height);
offScreenGraphics = Graphics.FromImage(offscreenBitmap);
if (BackgroundBitmap != null)
{
offScreenGraphics.DrawImage(BackgroundBitmap, 0, 0, BackgroundBitmap.Width, BackgroundBitmap.Height);
}
DrawCloseButton(offScreenGraphics);
DrawText(offScreenGraphics);
grfx.DrawImage(offscreenBitmap, 0, 0);
}
#endregion
private void InitializeComponent()
{
this.SuspendLayout();
this.ShowInTaskbar = false;
this.ClientSize = new System.Drawing.Size(284, 264);
this.Name = "TaskbarNotifier";
this.ResumeLayout(false);
}
}
#region Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage
public class ToastCollection
{
#region ToastCollection Private Members
protected int nToastCount = 0;
protected int nBaseWindowBottom = 0;
protected int nBaseWindowRight = 0;
#endregion
#region ToastCollection Public Methods
public ToastCollection()
{
nBaseWindowBottom = Convert.ToInt32(Application.UserAppDataRegistry.GetValue("ToastBottom", "0"));
nBaseWindowRight = Convert.ToInt32(Application.UserAppDataRegistry.GetValue("ToastRight", "0"));
}
public void AddToast(TaskbarNotifier newToast,
int screenTop,
ref int baseWindowBottom,
ref int baseWindowRight)
{
if (nBaseWindowBottom > (screenTop - newToast.Height))
{
if (nBaseWindowRight > newToast.Width)
nBaseWindowRight = 0;
else
nBaseWindowRight = nBaseWindowRight + newToast.Width + newToast.Padding;
nBaseWindowBottom = Convert.ToInt32(Application.UserAppDataRegistry.GetValue("ToastBottom", "0"));
}
nToastCount += 1;
baseWindowBottom = nBaseWindowBottom;
baseWindowRight = nBaseWindowRight;
nBaseWindowBottom = nBaseWindowBottom + newToast.Height + newToast.Padding;
}
public void KillWindow(TaskbarNotifier toast)
{
nToastCount -= 1;
if (nToastCount == 0)
{
nBaseWindowBottom = Convert.ToInt32(Application.UserAppDataRegistry.GetValue("ToastBottom", "0"));
nBaseWindowRight = Convert.ToInt32(Application.UserAppDataRegistry.GetValue("ToastRight", "0"));
}
toast.Close();
toast.Dispose();
}
#endregion
}
#endregion
}
I hope it will help you
_________________________________
/ Crusty.Applesniffer@free.fr \
|^^^^^^| /http:
| | |------------------------------------|
| | | |
| (o)(o) o | Programmers don't die, |
@ _) o | they just GOSUB without RETURN |
| ,___| o \ /
| / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/____\
|