fqy131314

C#绘制自定义小人

采用graphics库,代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //正方形
            Graphics graphics = this.CreateGraphics();
            Pen MyPen = new Pen(Color.Red, 5);
            graphics.DrawEllipse(MyPen, 350, 20, 80, 80);
            graphics.DrawRectangle(MyPen, 350, 100, 80, 100);
            graphics.DrawRectangle(MyPen, 320, 110, 30, 80);
            graphics.DrawRectangle(MyPen, 430, 110, 30, 80);
            graphics.DrawRectangle(MyPen, 390, 200, 30, 80);
            graphics.DrawRectangle(MyPen, 360, 200, 30, 80);

            //圆
            Graphics graphics1 = this.CreateGraphics();
            Brush brush = new SolidBrush(Color.Red);
            graphics1.FillEllipse(brush, 370, 50, 10, 10);
            graphics1.FillEllipse(brush, 400, 50, 10, 10);

            //圆弧
            Graphics ghs = this.CreateGraphics();
            Rectangle myRectangle = new Rectangle(365, 50, 50, 40);
            ghs.DrawArc(MyPen, myRectangle, -210, -120);

            ghs.FillPie(brush, 350, 80, 80, 80, 30, 120);

            //字
            string str1 = "我是帅比";

            Font myFont = new Font("宋体", 16, FontStyle.Bold);
            SolidBrush myBrush = new SolidBrush(Color.Black);
            Graphics myGraphics = this.CreateGraphics();
            myGraphics.DrawString(str, myFont, myBrush, 250, 380);

            Font myFont1 = new Font("楷体", 8, FontStyle.Bold);
            myGraphics.DrawString(str1, myFont1, myBrush, 360, 140);
        }
    }
}

成果图:

posted on   会飞的鱼-blog  阅读(40)  评论(1编辑  收藏  举报  

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
< 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

导航

统计

点击右上角即可分享
微信分享提示