The first line sets the background bitmap skin and transparency color (must be present), and the second line sets the 3-State close button with its transparency color and its location on the window (this line is optional if you don't want a close button).
Since I wanted to keep only managed code, I used the Screen.GetWorkingArea(WorkAreaRectangle) function instead of using unmanaged code to get the taskbar position. As a result, I made the popup always appear at the bottom of WorkAreaRectangle whichever position the taskbar has.
I didn't find any C# managed equivalent to the Win32 function ShowWindow(SW_SHOWNOACTIVATE) to make the popup, not steal the focus of the active window.
Updates
01 April 2003: Small bug fix in the OnMouseUp handler.
11 January 2003: Patrick Vanden Driessche updated both the C# and VB.NET versions:
The popup now doesn't close automatically when the mouse is still over it
The popup is shown again when it was disappearing and the mouse comes over it
A few other bugs have been corrected.
10 January 2003: A port of TaskbarNotifier has been done by Patrick Vanden Driessche in VB.NET
05 December 2002: The popup is now shown using the Win32 function ShowWindow(SW_SHOWNOACTIVATE), to prevent the popup from stealing the focus.
Conclusion
I hope this code will be useful to you. If you have suggestions to enhance this class functionalities, please post a comment.
As i mentioned as the subject title ,and could i add some button in the pop up windows??how to do that ??i am new to c# ,help !i will appreciate your help! ;P
no body replied !!!!!! ok ,i already fix it up by myself ,another question,how to make a lot of message in the right corner according to the sequence of the time ?????please ,somebody help me !!!
Hi, I am using VB.NET 2008 [comming from vb 6, this is a big jump], when I open the project [downloaded one] it converted it to vb.net 2008. I get an error message stating that "Resource file 'TaskBarNotifier.resx' can't not be found". I am sorry if I sound dumm but what is a resx file? Should there be one? There isn't one for TaskBarNotifier.vb but there is one for Form1.vb.
I ran into the same problem. To correct it I clicked on the form name in solution explorer and removed the resource file under it. I also did this for form1. Once done, I rebuilt the project and ran it. Worked great after that.
I am currently prototyping a UI and want to make use of this popup window. I need to extend it and modify the inheritance (will inherit from DevExpress derivative of WinForm) to improve the applications look and feel. Your code is the only that I have found that extends WinForm and looks like it can be modified. Your code did not have any license information contained in it, is it alright to use it in commercial code?
I can send you my email address if you want to take this discussion out of the message board.
You shouldn't dispose the grfx object: one of those things that will probably result in undefined behaviour. Rule of the thumb with the .Net framework is that you shouldn't dispose something if the BCLs handed it to you. For example the .Net framework may actually be doing the following:
... using(Graphics g = Graphics.FromImage(tmpImage)) { PaintEventArgs pve = new PaintEventArgs(g); targetForm.OnPaintBackground(pve); g.Save(); // If OnPaintBackground was disposed an ObjectDisposedException will be thrown here. } ...
This applies to .Net 1.1 and is general advice which relates to the usage of this notifier and as such requires no modification of the original source.
I needed to wait 5 seconds after an event occurred before showing the notifier dialog. If you use a standard timer it's call back will execute on a different thread (not the UI thread), this thread will draw the notifier but the user will be unable to click on it.
When you instantiate the delay timer you must set the SynchronisationObject to your main UI form. This will ensure that the callback event is fired on the UI thread.
Hi, I used your code (and parts of the contribution from Crusty Applesniffer) in a freeware application that monitors xPL messages traffic (xPL is used in home automation projects). You can find it here: http://blog.boxedbits.com/xpl#xplballoon[^] Thank you for making your excellent code available! Tom
hola tengo un problema cree una biblioteca de clases y agregue todo el codigo seguidamente cree un proyecto en el cual es un servio de windows desde alli llama el dll pero no me muestra nada , le mando mensajes pero no aparece....... ¡no sabes que hacer?
Hi. I'm trying to change the code so i can put the popup where ever i want on the screen. I have changed the Me._rectWorkArea.Right - Me._bmpBackground.Width - 17 and the Me._rectWorkArea.Bottom - 1 values to numbers im picking from a menu but I've encountered 2 problems: 1. sometimes (especially if there's a popup already on screen) the popup still appears on the botton right corner. 2. The last line of the image is dropping down to the bottom of the screen instead of dissapearing where i put the x,y coordinates. Any thoughts? btw - Im using VB Express 2005
The following worked for me, if it is the correct way I don't know
Protected Sub OnTimer(ByVal sender As Object, ByVal e As EventArgs)
Select Case Me._eWindowState
Case TaskbarStates.Appearing
If Height < Me._bmpBackground.Height Then SetBounds(Left, Top - Me._iIncrementShow, Width, Height + Me._iIncrementShow) Else Me._tmrAnimation.Stop() Height = Me._bmpBackground.Height Me._tmrAnimation.Interval = Me._iVisibleEvents Me._eWindowState = TaskbarStates.Visible Me._tmrAnimation.Start() End If
Case TaskbarStates.Visible
Me._tmrAnimation.Stop() Me._tmrAnimation.Interval = Me._iHideEvents ' Rev 002 If ((Me._bKeepVisibleOnMouseOver) AndAlso (Not Me._bMouseOverPopup)) OrElse _ (Not Me._bKeepVisibleOnMouseOver) Then Me._eWindowState = TaskbarStates.Disappearing End If Me._tmrAnimation.Start()
Case TaskbarStates.Disappearing
' Rev 002 If (Me._bReShowOnMouseOver) AndAlso (Me._bMouseOverPopup) Then Me._eWindowState = TaskbarStates.Appearing Else If Top < Me._rectWorkArea.Bottom Then If Height = 2 Then Hide() Exit Sub Else SetBounds(Left, Top + Me._iIncrementHide, Width, Height - Me._iIncrementHide) End If Else Hide() End If End If
this is very very useful for me hope it's very useful for all of our code project members.this is the first source which i see the code for the graphical. thank you again for the sharing it.
Finally, below, there is the full updated class and the new ToastCollection class (sorry for size and format)
// C# TaskbarNotifier Class v1.0 // by John O'Byrne - 02 december 2002 // 01 april 2003 : Small fix in the OnMouseUp handler // 11 january 2003 : Patrick Vanden Driessche <pvdd@devbrains.be> added a few enhancements // Small Enhancements/Bugfix // Small bugfix: When Content text measures larger than the corresponding ContentRectangle // the focus rectangle was not correctly drawn. This has been solved. // Added KeepVisibleOnMouseOver // Added ReShowOnMouseOver // Added If the Title or Content are too long to fit in the corresponding Rectangles, // the text is truncateed and the ellipses are appended (StringTrimming). // Rev 003-CrustyAppleSniffer: Sliding or fading effect // Rev 004-CrustyAppleSniffer: New Property: Padding // Rev 005-CrustyAppleSniffer: New feature: Management of Toasts' Collection and last position storage // Rev 006-CrustyAppleSniffer: New feature: Content alignement using System; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using System.Windows.Forms; using System.Runtime.InteropServices;
namespace CustomUIControls { /// <summary> /// TaskbarNotifier allows to display Skinned instant messaging popups /// </summary> 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; // Added Rev 002 protected bool bReShowOnMouseOver = false; // Added Rev 002 protected bool bAppearBySliding = true; // Rev 003-CAS: Sliding or fading effect protected int nPadding = 10; // Rev 004-CAS: New Property: Padding protected int nBaseWindowBottom = 0; // Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage protected int nBaseWindowRight = 0; // Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage protected ToastCollection colBase = null; // Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage protected bool bMoving = false; // Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage protected int nMouseDownX; // Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage protected int nMouseDownY; // Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage protected ContentAlignment caContentAlignement; // Rev 006-CAS: New feature: Content alignement
#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 /// <summary> /// List of the different popup animation status /// </summary> public enum TaskbarStates { hidden = 0, appearing = 1, visible = 2, disappearing = 3 } #endregion
#region TaskbarNotifier Constructor /// <summary> /// The Constructor for TaskbarNotifier /// </summary> public TaskbarNotifier() { // Window Style FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Minimized; //-CAS 29/08/2007: avoid taskbar flickering each time a Notifier is displayed // base.Show(); 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 /// <summary> /// Get the current TaskbarState (hidden, showing, visible, hiding) /// </summary> public TaskbarStates TaskbarState { get { return taskbarState; } }
/// <summary> /// Get/Set the popup Title Text /// </summary> public string TitleText { get { return titleText; } set { titleText = value; Refresh(); } }
/// <summary> /// Get/Set the popup Content Text /// </summary> public string ContentText { get { return contentText; } set { contentText = value; Refresh(); } }
/// <summary> /// Get/Set the Normal Title Color /// </summary> public Color NormalTitleColor { get { return normalTitleColor; } set { normalTitleColor = value; Refresh(); } }
/// <summary> /// Get/Set the Hover Title Color /// </summary> public Color HoverTitleColor { get { return hoverTitleColor; } set { hoverTitleColor = value; Refresh(); } }
/// <summary> /// Get/Set the Normal Content Color /// </summary> public Color NormalContentColor { get { return normalContentColor; } set { normalContentColor = value; Refresh(); } }
/// <summary> /// Get/Set the Hover Content Color /// </summary> public Color HoverContentColor { get { return hoverContentColor; } set { hoverContentColor = value; Refresh(); } }
/// <summary> /// Get/Set the Normal Title Font /// </summary> public Font NormalTitleFont { get { return normalTitleFont; } set { normalTitleFont = value; Refresh(); } }
/// <summary> /// Get/Set the Hover Title Font /// </summary> public Font HoverTitleFont { get { return hoverTitleFont; } set { hoverTitleFont = value; Refresh(); } }
/// <summary> /// Get/Set the Normal Content Font /// </summary> public Font NormalContentFont { get { return normalContentFont; } set { normalContentFont = value; Refresh(); } }
/// <summary> /// Get/Set the Hover Content Font /// </summary> public Font HoverContentFont { get { return hoverContentFont; } set { hoverContentFont = value; Refresh(); } }
/// <summary> /// Indicates if the popup should remain visible when the mouse pointer is over it. /// Added Rev 002 /// </summary> public bool KeepVisibleOnMousOver { get { return bKeepVisibleOnMouseOver; } set { bKeepVisibleOnMouseOver = value; } }
/// <summary> /// Indicates if the popup should appear again when mouse moves over it while it's disappearing. /// Added Rev 002 /// </summary> public bool ReShowOnMouseOver { get { return bReShowOnMouseOver; } set { bReShowOnMouseOver = value; } }
/// <summary> /// Indicates if the popup should diplayed with fadding or slidding effect /// Added Rev 003-CAS /// </summary> public bool AppearBySliding { get { return bAppearBySliding; } set { bAppearBySliding = value; } } /// <summary> /// Get/Set the popup padding (distance between 2 popups) /// Added Rev 004-CAS: New Property: Padding /// </summary> public new int Padding { get { return nPadding; } set { nPadding = value; Refresh(); } } /// <summary> /// Get/Set the popup distance from the working area bottom border due to popup stacking /// Added Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage /// </summary> public int BaseWindowBottom { get { return nBaseWindowBottom; } set { nBaseWindowBottom = value; Refresh(); } } /// <summary> /// Get/Set the popup distance from the working area right border due to popup stacking /// Added Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage /// </summary> public int BaseWindowRight { get { return nBaseWindowRight; } set { nBaseWindowRight = value; Refresh(); } } /// <summary> /// Get/Set the toast collection the popup belongs to /// Added Rev 005-CAS: New feature: Management of Toasts' Collection and last position storage /// </summary> public ToastCollection Base { get { return colBase; } set { colBase = value; Refresh(); } } /// <summary> /// Get/Set the Content alignement property /// Added Rev 006-CAS: New feature: Content alignement /// </summary> public ContentAlignment ContentTextAlignement { get { return caContentAlignement; } set { caContentAlignement = value; Refresh(); } } #end