首页 > Windows开发 > 详细

动态绘制任务栏图标C#的实现

时间:2016-05-24 16:45:10      阅读:494      评论:0      收藏:0      [点我收藏+]

通常我们在做一个应用时会遇到这样的需求:将收到的消息条数显示到任务栏,比如如下的效果

技术分享

 

怎么实现呢?

 

代码如下:

 /// <summary>
/// 动态设置任务栏图标
/// </summary>
/// <param name="number"></param>
public void SetTaskIconDynamic(string number) { //动态绘制图标样式 Size size = this.Icon.Size; Bitmap cursorBitmap = new Bitmap(size.Width, size.Height); Graphics graphics = Graphics.FromImage(cursorBitmap); graphics.Clear(Color.FromArgb(0, 0, 0, 0)); graphics.ResetClip(); Rectangle rect = new Rectangle(0, 0, size.Width, size.Height);

//Gdi+自定义绘制图标 graphics.DrawImage(
this.Icon.ToBitmap(), rect); graphics.FillEllipse(new SolidBrush(Color.FromArgb(244,107,10)), new Rectangle(rect.Width / 2 - 2, rect.Height / 2 - 2, rect.Width / 2, rect.Height / 2)); graphics.DrawString(number, this.Font, Brushes.White, new Rectangle(rect.Width / 2 - 2, rect.Height / 2 - 2, rect.Width / 2, rect.Height / 2), new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); //生成Icon Icon cursor = Icon.FromHandle(cursorBitmap.GetHicon()); graphics.Dispose(); cursorBitmap.Dispose(); //更新任务栏图标样式 this.Icon = cursor; }

拿走,不谢!

 

动态绘制任务栏图标C#的实现

原文:http://www.cnblogs.com/shaozhuyong/p/5523827.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!