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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-20 我要评论
想了解C#实现带消息数的App图标的相关内容吗,在本文为您仔细讲解C#实现带消息数的App图标的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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(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();
    }

  }
}

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们