C#绘制自定义小人

简介: 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);
        }
    }
}

成果图:



7f041ec857f04422852a28563bbe1307.png

相关文章
|
8月前
|
关系型数据库 MySQL C#
C# winform 一个窗体需要调用自定义用户控件的控件名称
给用户控件ucQRCode增加属性: //二维码图片 private PictureBox _pictureBoxFSHLQrCode; public PictureBox PictureBoxFSHLQrCode {   get { return _pictureBoxFSHLQrCode; }   set { this.pictureBoxFSHLQrCode = value; } } 在Form1窗体直接调用即可: ucQRCode uQRCode=new ucQRCode(); ucQRCode.PictureBoxFSHLQrCode.属性= 要复制或传给用户控件上的控件的值
40 0
|
21天前
|
移动开发 JavaScript 安全
C# 实现微信自定义分享
C# 实现微信自定义分享
|
21天前
|
C#
C#学习相关系列之自定义遍历器
C#学习相关系列之自定义遍历器
|
9月前
|
编译器 C#
c# 自定义扩展方法
c# 自定义扩展方法
|
8月前
|
编译器 C#
C#中导入其它自定义的命名空间
c#中怎么导入其它自定义的命名空间首先要确保已经导入了想要导入的自定义的命名空间。如上图这时编译器应该会报错,此时就需要手动去添加引用了,cs文件默认没有添加引用,只是加载了想要导入的命名空间,但是没有添加引用,所以需要自己要手动添加引用。切记!然后会有一个对话框选择你想引用的命名空间,点击确定即可。注意:一般而言,C#中如果没有改变那么一般项目的类名都默认是Program,在引用时需要注...
73 1
C#中导入其它自定义的命名空间
C#或Winform中的消息通知之自定义优雅漂亮的通知效果
Custom Notification自定义通知提示,一款非常优雅漂亮的自定义通知效果,主要介绍其实现思路、调整和优化...
920 0
C#或Winform中的消息通知之自定义优雅漂亮的通知效果
|
存储 设计模式 缓存
C# 实现 key-value 结构自定义缓存 CustomCache
C# 实现 key-value 结构自定义缓存 CustomCache
136 1
C# 实现 key-value 结构自定义缓存 CustomCache
|
开发框架 JSON 前端开发
【C#】.net core2.1,自定义全局类对API接口和视图页面产生的异常统一处理
在开发一个网站项目时,异常处理和过滤功能是最基础的模块 本篇文章就来讲讲,如何自定义全局异常类来统一处理
213 0
|
数据库 C# 数据库管理
C#:Winfrom 实现DataGridView 自定义分页
今天给大家分享Winform实现DataGridView 自定义分页的案例,感兴趣的朋友可以一起来学习一下。 采用技术:C\#+Winform+Dapper+SQLite。
C#:Winfrom 实现DataGridView 自定义分页
C#编程-103:自定义泛型类
C#编程-103:自定义泛型类
C#编程-103:自定义泛型类