雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

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

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊:

上次寫了一篇博文,但是每次更新圖標時,桌面會閃爍(刷新)//www.jb51.net/article/73350.htm,有博友說人家的圖標都不會刷新,還能動畫.我想了一下,如果要達到這個效果,可以用Form來實現,就是在Form中嵌入一個圖片,然后用一個label來動態(tài)顯示消息數,關鍵是將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#代碼實現對AES加密解密

欄    目:C#教程

下一篇:C#使用ImitateLogin模擬登錄百度

本文標題:C#實現帶消息數的App圖標

本文地址:http://www.jygsgssxh.com/a1/C_jiaocheng/6783.html

網頁制作CMS教程網絡編程軟件編程腳本語言數據庫服務器

如果侵犯了您的權利,請與我們聯系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網 版權所有