采用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);
}
}
}
成果图: