C#实现带消息数的App图标
作者:hebedich 时间:2022-03-08 11:30:52
上次写了一篇博文,但是每次更新图标时,桌面会闪烁(刷新)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();
}
}
}
标签:C#,App图标
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring使用ThreadPoolTaskExecutor自定义线程池及异步调用方式
2022-07-22 21:53:32
解决MyEclipse中Maven设置jdk版本jdk1.8报错问题
2022-04-20 18:19:04
![](https://img.aspxhome.com/file/2023/1/81321_0s.png)
SpringBoot拦截器的使用
2023-04-27 23:27:27
![](https://img.aspxhome.com/file/2023/7/91077_0s.png)
java取两个字符串的最大交集
2021-07-30 17:23:08
C#使用HttpPost请求调用WebService的方法
2022-02-24 07:22:16
![](https://img.aspxhome.com/file/2023/8/89848_0s.png)
C# lambda表达式原理定义及实例详解
2021-07-26 21:44:44
java实现超市管理系统
2022-06-23 13:19:06
![](https://img.aspxhome.com/file/2023/4/106124_0s.jpg)
Vue3源码解读effectScope API及实现原理
2023-12-11 19:28:49
如何利用JAVA实现走迷宫程序
2022-06-23 10:52:06
![](https://img.aspxhome.com/file/2023/3/62983_0s.png)
Java 获取当前时间及实现时间倒计时功能【推荐】
2022-08-21 16:08:27
![](https://img.aspxhome.com/file/2023/7/75657_0s.png)
详解Spring ApplicationContext加载过程
2023-07-17 01:07:43
java 中如何实现 List 集合去重
2023-10-07 07:54:06
![](https://img.aspxhome.com/file/2023/9/58549_0s.webp)
android编程实现图片库的封装方法
2023-12-20 07:51:27
Flutter刷新组件RefreshIndicator自定义样式demo
2023-07-06 15:56:45
![](https://img.aspxhome.com/file/2023/2/58272_0s.webp)
Android Studio 3.6 layout文件text模式切换问题
2022-10-06 11:28:32
![](https://img.aspxhome.com/file/2023/5/108255_0s.png)
java实现简单的图书管理系统
2022-11-25 03:30:11
![](https://img.aspxhome.com/file/2023/8/61778_0s.png)
Android startService的使用与Service生命周期案例详解
2021-07-14 01:51:24
![](https://img.aspxhome.com/file/2023/8/93338_0s.png)
Scala可变参数列表,命名参数和参数缺省详解
2022-09-26 21:00:49
解决Eclipse创建android项目无法正常预览布局文件问题的方法
2023-07-31 09:51:12
![](https://img.aspxhome.com/file/2023/6/82316_0s.png)
jenkins安装及其配置笔记
2022-10-03 11:01:19
![](https://img.aspxhome.com/file/2023/8/64048_0s.png)