Usually we encounter the need to do an application: To display the number of received message bars to the taskbar, such as the following effect
How to achieve it?
The code is as follows:
<summary>
///dynamically set the taskbar icon
</summary>
<param name= "Number" ></param>
Public voidSettaskicondynamic (stringNumber ) { //dynamically draw icon StylesSize size = This. Icon.size; Bitmap Cursorbitmap=NewBitmap (size. Width, size. Height); Graphics Graphics=graphics.fromimage (CURSORBITMAP); Graphics. Clear (Color.FromArgb (0,0,0,0)); Graphics. Resetclip (); Rectangle rect=NewRectangle (0,0, size. Width, size. Height);
//gdi+ Custom draw icon graphics. DrawImage ( This. Icon.tobitmap (), rect); Graphics. FillEllipse (NewSolidBrush (Color.FromArgb (244,107,Ten)),NewRectangle (rect. Width/2-2, Rect. Height/2-2, Rect. Width/2, Rect. Height/2)); Graphics. DrawString (number, This. Font, Brushes.white,NewRectangle (rect. Width/2-2, Rect. Height/2-2, Rect. Width/2, Rect. Height/2),NewStringFormat () {linealignment=Stringalignment.center, Alignment=stringalignment.center}); //Generate iconIcon cursor =Icon.fromhandle (Cursorbitmap.gethicon ()); Graphics. Dispose (); Cursorbitmap.dispose (); //update taskbar icon style This. Icon =cursor;}
Take it, no thanks!
Dynamically drawing the taskbar icon implementation of C #