Dynamically drawing the taskbar icon implementation of C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.