欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-01-02 16:26:52
上次写了一篇博文,但是每次更新图标时,桌面会闪烁(刷新),有博友说人家的图标都不会刷新,还能动画.我想了一下,如果要达到这个效果,可以用form来实现,就是在form中嵌入...

上次写了一篇博文,但是每次更新图标时,桌面会闪烁(刷新),有博友说人家的图标都不会刷新,还能动画.我想了一下,如果要达到这个效果,可以用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(116, 164, 2);
      this.transparencykey = this.backcolor; 
      
    }

    private void appiconmsg_load(object sender, eventargs e)
    {
      this.width = 64;
      this.height = 64;
      this.label1.text = "99";
      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 = 0;
    private void timer1_tick(object sender, eventargs e)
    {
      int num = new random().next(1, 100);
      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图标

上一篇:

下一篇: