欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

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

时间:2021-04-27 09:09:03|栏目:.NET代码|点击:

上次写了一篇博文,但是每次更新图标时,桌面会闪烁(刷新)https://www.jb51.net/article/73350.htm,有博友说人家的图标都不会刷新,还能动画.我想了一下,如果要达到这个效果,可以用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();
    }

  }
}

上一篇:asp.net 上传或下载当文件名包含有特殊字符"#"的处理

栏    目:.NET代码

下一篇:使用C#来编写一个异步的Socket服务器

本文标题:C#实现带消息数的App图标

本文地址:http://www.codeinn.net/misctech/109837.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有