c# 自绘图标
//绘制一个下拉菜单按钮 private void drawMenuFlag(int lineWidth, PictureBox picture) { // 创建一个与 PictureBox 大小相同的 Bitmap Bitmap bmp = new Bitmap(picture.Width, picture.Height); // 创建一个 Graphics 对象,用于在 Bitmap 上绘制图形 using (Graphics g = Graphics.FromImage(bmp)) { // 启用抗锯齿 g.SmoothingMode = SmoothingMode.AntiAlias; // 设置线条的颜色和宽度 Pen pen = new Pen(Color.White, lineWidth); // 绘制横线 g.DrawLine(pen, 0, 1, picture.Width, 1); // 定义三角形的三个顶点 Point point1 = new Point(0, 5); Point point2 = new Point(picture.Width /2, picture.Height -1); Point point3 = new Point(picture.Width, 5); // 构建三角形的顶点数组 Point[] trianglePoints = { point1, point2, point3 }; // 使用绘图对象绘制三角形 g.DrawPolygon(pen, trianglePoints); } // 将绘制好的 Bitmap 显示在 PictureBox 中 picture.Image = bmp; } //绘制关闭按钮 private void drawCloseFlag(int lineWidth, PictureBox picture) { // 创建一个与 PictureBox 大小相同的 Bitmap Bitmap bmp = new Bitmap(picture.Width, picture.Height); // 创建一个 Graphics 对象,用于在 Bitmap 上绘制图形 using (Graphics g = Graphics.FromImage(bmp)) { // 启用抗锯齿 g.SmoothingMode = SmoothingMode.AntiAlias; // 设置线条的颜色和宽度 Pen pen = new Pen(Color.White, lineWidth); // 计算叉的四个点 Point topLeft = new Point(1, 1); Point bottomRight = new Point(picture.Width, picture.Height); Point topRight = new Point(picture.Width, 0); Point bottomLeft = new Point(0, picture.Height); // 绘制叉 g.DrawLine(pen, topLeft, bottomRight); g.DrawLine(pen, topRight, bottomLeft); } // 将绘制好的 Bitmap 显示在 PictureBox 中 picture.Image = bmp; } //绘制最小化按钮 private void drawMinimizeFlag(int lineWidth, PictureBox picture) { // 创建一个与 PictureBox 大小相同的 Bitmap Bitmap bmp = new Bitmap(picture.Width, picture.Height); // 创建一个 Graphics 对象,用于在 Bitmap 上绘制图形 using (Graphics g = Graphics.FromImage(bmp)) { // 启用抗锯齿 g.SmoothingMode = SmoothingMode.AntiAlias; // 设置线条的颜色和宽度 Pen pen = new Pen(Color.White, lineWidth); // 绘制横线 g.DrawLine(pen, 0, picture.Height / 2 + lineWidth / 2, picture.Width, picture.Height / 2 + lineWidth / 2); } // 将绘制好的 Bitmap 显示在 PictureBox 中 picture.Image = bmp; }
桂棹兮兰桨,击空明兮溯流光。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
2014-04-01 通过JavaScript更新UpdatePanel备忘