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 2022-11-06 14:47 会飞的鱼-blog 阅读(40) 评论(1) 编辑 收藏 举报 来源
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!