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; }
桂棹兮兰桨,击空明兮溯流光。