C# 如何实现带消息数的App图标

  上次写了一篇博文,但是每次更新图标时,桌面会闪烁(刷新),有博友说人家的图标都不会刷新,还能动画.我想了一下,如果要达到这个效果,可以用Form来实现,就是在Form中嵌入一个图片,然后用一个label来动态显示消息数,关键是将Form的边框隐藏,背景设为透明即可.如果要有旋转或者缩放动画,都可以用C#来实现.

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace AOPDemo
{
public partial class AppIconMsg : Form
{
public AppIconMsg()
{
InitializeComponent();
//设置背景为透明
this.BackColor = Color.FromArgb(, , );
this.TransparencyKey = this.BackColor; } private void AppIconMsg_Load(object sender, EventArgs e)
{
this.Width = ;
this.Height = ;
this.label1.Text = "";
this.timer1.Enabled = true; } // Drag it around the screen
private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
protected override void WndProc(ref Message m)
{
//Disable mouseDoubleClick on form
if (m.Msg == WM_LBUTTONDBLCLK)
{
Form2 frm = new Form2(msg);
frm.Show();
//this.Close();
return;
} if (m.Msg == WM_NCLBUTTONDBLCLK)
{
Form2 frm = new Form2(msg);
frm.Show();
// this.Close();
return;
} //drag
if (m.Msg == WM_NCHITTEST)
m.Result = new IntPtr(HTCAPTION);
else
base.WndProc(ref m);
}
private int msg = ;
private void timer1_Tick(object sender, EventArgs e)
{
int num = new Random().Next(, );
msg = num;
this.label1.Text = num.ToString();
} const int WM_LBUTTONDBLCLK = 0x0203;//client area
const int WM_NCLBUTTONDBLCLK = 0x00A3;//non-client area
private void toolStripExit_Click(object sender, EventArgs e)
{
this.Close();
} }
}

C# 如何实现带消息数的App图标

C# 如何实现带消息数的App图标

上一篇:为什么C++中空类和空结构体大小为1?(转载)


下一篇:android点击桌面App图标activity启动流程