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;
}
复制代码

 

posted on   空明流光  阅读(59)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
历史上的今天:
2014-04-01 通过JavaScript更新UpdatePanel备忘

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示