This is the TaskbarNotifier, a skinnable MSN Messenger-like popup in C # and now in VB. NET too By John O' Byrne. it's a pity that the article I wrote last night was written. After, the date can only be recorded in today's name. I didn't find the place where I changed the article time in my blog: |
[Introduction]
When I learned C #, I transplanted my C ++ CTaskbarNotifier class to implement this skin-changing MSN Messenger-like style form, in a certain style, it looks very similar to the pop-up window of MSN Messenger.
[Features]
Supported:
1. Customizable transparent bitmap background
2. The button can be changed and there are three statuses to close
3. Title text that can be clicked
4. content text that can be clicked
5. A selection rectangle
6. Customizable font and color of text in different States (normal/mouse hover)
7. There are parameters to control the speed at which the animation moves in and out.
[Compatibility]
This class can be run independently. Except for the. NET basic class library, no other libraries are required. It can be written in managed code with good portability.
[How to use]
- First, copyTaskbarNotifier. csGo to your project directory.
- Add using CustomUIControls at the top of your code;
- Add a member variable in your class: TaskbarNotifier taskbarNotifier;
- Add taskbarNotifier = new TaskbarNotifier () in your class constructor ();
TaskbarNotifier. SetBackgroundBitmap ("skin.bmp ",
Color. FromArgb (255 ));
TaskbarNotifier. SetCloseBitmap ("close.bmp ",
Color. FromArgb (255, 0, 255), new Point (127,8 ));
TaskbarNotifier. TitleRectangle = new Rectangle );
TaskbarNotifier. ContentRectangle = new Rectangle (8, 41, 133,68 );
TaskbarNotifier. TitleClick + = new EventHandler (TitleClick );
TaskbarNotifier. ContentClick + = new EventHandler (ContentClick );
TaskbarNotifier. CloseClick + = new EventHandler (CloseClick );
The last line indicates that the pop-up time of the form is 500 ms, the display duration is 3000 ms, and the disappearance duration is 500 ms.
[Manual]
Method
Void Show (string strTitle, string strContent, int nTimeToShow, int nTimeToStay, int nTimeToHide );
Void Hide ();
Void SetBackgroundBitmap (string strFilename, Color transparencyColor );
Void SetBackgroundBitmap (Image image, Color transparencyColor );
Void SetCloseBitmap (string strFilename, Color transparencyColor, Point position );
Void SetCloseBitmap (Image image, Color transparencyColor, Point position );
Attribute
String TitleText (get/set)
String ContentText (get/set)
TaskbarStates TaskbarState (get)
Color NormalTitleColor (get/set)
Color HoverTitleColor (get/set)
Color NormalContentColor (get/set)
Color HoverContentColor (get/set)
Font NormalTitleFont (get/set)
Font HoverTitleFont (get/set)
Font NormalContentFont (get/set)
Font HoverContentFont (get/set)
Rectangle TitleRectangle (get/set) // must be defined before calling show ())
Rectangle ContentRectangle (get/set) // must be defined before calling show ())
Bool TitleClickable (get/set) (default = false );
Bool ContentClickable (get/set) (default = true );
Bool CloseClickable (get/set) (default = true );
Bool EnableSelectionRectangle (get/set) (default = true );
Event
Event EventHandler CloseClick
Event EventHandler TitleClick
Event EventHandler ContentClick
[Technical Details]
The skin of a form is dynamically drawn in an area by specifying the image and transparent color.
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 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;
}
Refresh () of the form uses double buffering technology to avoid blinking 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 );
}
[Bug/restriction]
To use only the managed code, the Screen. GetWorkingArea (WorkAreaRectangle) function is used to obtain the location of the taskbar. The result is that the form always appears at the bottom of WorkAreaRectangle.
Not found in C # managed codeShowWindow(SW_SHOWNOACTIVATE)
To make the form appear, but do not steal the focus of the current window.