C# 如何實現帶消息數的App圖標


  上次寫了一篇博文,但是每次更新圖標時,桌面會閃爍(刷新),有博友說人家的圖標都不會刷新,還能動畫.我想了一下,如果要達到這個效果,可以用Form來實現,就是在Form中嵌入一個圖片,然后用一個label來動態顯示消息數,關鍵是將Form的邊框隱藏,背景設為透明即可.如果要有旋轉或者縮放動畫,都可以用C#來實現.

 1 using System;  2 using System.Collections.Generic;  3 using System.ComponentModel;  4 using System.Data;  5 using System.Drawing;  6 using System.Linq;  7 using System.Text;  8 using System.Windows.Forms;  9 
10 namespace AOPDemo 11 { 12     public partial class AppIconMsg : Form 13  { 14         public AppIconMsg() 15  { 16  InitializeComponent(); 17             //設置背景為透明
18             this.BackColor = Color.FromArgb(116, 164, 2); 19             this.TransparencyKey = this.BackColor; 20             
21  } 22 
23         private void AppIconMsg_Load(object sender, EventArgs e) 24  { 25             this.Width = 64; 26             this.Height = 64; 27             this.label1.Text = "99"; 28             this.timer1.Enabled = true; 29             
30  } 31 
32         // Drag it around the screen
33         private const int WM_NCHITTEST = 0x84; 34         private const int HTCAPTION = 0x2; 35         protected override void WndProc(ref Message m) 36  { 37             //Disable mouseDoubleClick on form
38             if (m.Msg == WM_LBUTTONDBLCLK) 39  { 40                 Form2 frm = new Form2(msg); 41  frm.Show(); 42                 //this.Close();
43                 return; 44  } 45 
46             if (m.Msg == WM_NCLBUTTONDBLCLK) 47  { 48                 Form2 frm = new Form2(msg); 49  frm.Show(); 50                // this.Close();
51                 return; 52  } 53 
54             //drag
55             if (m.Msg == WM_NCHITTEST) 56                 m.Result = new IntPtr(HTCAPTION); 57             else
58                 base.WndProc(ref m); 59  } 60         private int msg = 0; 61         private void timer1_Tick(object sender, EventArgs e) 62  { 63             int num = new Random().Next(1, 100); 64             msg = num; 65             this.label1.Text = num.ToString(); 66  } 67 
68         const int WM_LBUTTONDBLCLK = 0x0203;//client area
69         const int WM_NCLBUTTONDBLCLK = 0x00A3;//non-client area
70         private void toolStripExit_Click(object sender, EventArgs e) 71  { 72             this.Close(); 73  } 74 
75  } 76 }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM