add: 久坐提醒项目文件
This commit is contained in:
67
IconGenerator.cs
Normal file
67
IconGenerator.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.IO;
|
||||
|
||||
namespace TimerApp
|
||||
{
|
||||
public static class IconGenerator
|
||||
{
|
||||
public static Icon GenerateClockIcon()
|
||||
{
|
||||
int size = 64;
|
||||
using (Bitmap bmp = new Bitmap(size, size))
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.Clear(Color.Transparent);
|
||||
|
||||
// 绘制闹钟主体
|
||||
int margin = 4;
|
||||
int clockSize = size - margin * 2;
|
||||
Rectangle rect = new Rectangle(margin, margin, clockSize, clockSize);
|
||||
|
||||
// 外圈
|
||||
using (Pen pen = new Pen(Color.White, 4))
|
||||
{
|
||||
g.DrawEllipse(pen, rect);
|
||||
}
|
||||
|
||||
// 两个耳朵 (闹钟铃)
|
||||
using (Brush earBrush = new SolidBrush(Color.White))
|
||||
{
|
||||
// 左耳
|
||||
g.FillPie(earBrush, 0, 0, size/2, size/2, 200, 50);
|
||||
// 右耳
|
||||
g.FillPie(earBrush, size/2, 0, size/2, size/2, 290, 50);
|
||||
}
|
||||
|
||||
// 重绘外圈盖住耳朵连接处
|
||||
using (Brush bgBrush = new SolidBrush(Color.FromArgb(30, 30, 30))) // 深色背景
|
||||
{
|
||||
g.FillEllipse(bgBrush, rect);
|
||||
}
|
||||
using (Pen pen = new Pen(Color.White, 3))
|
||||
{
|
||||
g.DrawEllipse(pen, rect);
|
||||
}
|
||||
|
||||
// 指针
|
||||
Point center = new Point(size / 2, size / 2);
|
||||
using (Pen handPen = new Pen(Color.LightGreen, 3))
|
||||
{
|
||||
handPen.EndCap = LineCap.Round;
|
||||
// 时针
|
||||
g.DrawLine(handPen, center, new Point(center.X + 10, center.Y - 10));
|
||||
// 分针
|
||||
g.DrawLine(handPen, center, new Point(center.X, center.Y - 18));
|
||||
}
|
||||
|
||||
// 转换为图标
|
||||
// 注意:GetHicon 需要释放
|
||||
IntPtr hIcon = bmp.GetHicon();
|
||||
return Icon.FromHandle(hIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user