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

相关文章
|
关系型数据库 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.属性= 要复制或传给用户控件上的控件的值
87 0
|
8月前
|
C# C++
C# 自定义时间进度条
本文作者通过参考leslie_xin的一篇文章,成功创建了一个自定义的WinForms控件——时间进度条,该控件带有时间刻度和多种可定制的属性,如颜色、时间间隔等。作者在控件中加入了开始和结束时间,以及自适应的时间刻度间隔。控件能根据设置显示时间标签,并提供了事件处理,如值改变时的触发。代码中包含了计算时间刻度、绘制刻度线和时间标签的逻辑。作者强调了避免循环调用事件、使用OnXXX()形式的事件处理函数以及注意自定义控件中的属性和事件设计。
175 7
|
6月前
|
开发框架 .NET 编译器
总结一下 C# 如何自定义特性 Attribute 并进行应用
总结一下 C# 如何自定义特性 Attribute 并进行应用
166 1
|
编译器 C#
c# 自定义扩展方法
c# 自定义扩展方法
|
9月前
|
移动开发 JavaScript 安全
C# 实现微信自定义分享
C# 实现微信自定义分享
|
9月前
|
C#
C#学习相关系列之自定义遍历器
C#学习相关系列之自定义遍历器
C#或Winform中的消息通知之自定义优雅漂亮的通知效果
Custom Notification自定义通知提示,一款非常优雅漂亮的自定义通知效果,主要介绍其实现思路、调整和优化...
1327 0
C#或Winform中的消息通知之自定义优雅漂亮的通知效果
|
编译器 C#
C#中导入其它自定义的命名空间
c#中怎么导入其它自定义的命名空间首先要确保已经导入了想要导入的自定义的命名空间。如上图这时编译器应该会报错,此时就需要手动去添加引用了,cs文件默认没有添加引用,只是加载了想要导入的命名空间,但是没有添加引用,所以需要自己要手动添加引用。切记!然后会有一个对话框选择你想引用的命名空间,点击确定即可。注意:一般而言,C#中如果没有改变那么一般项目的类名都默认是Program,在引用时需要注...
125 1
C#中导入其它自定义的命名空间
|
存储 设计模式 缓存
C# 实现 key-value 结构自定义缓存 CustomCache
C# 实现 key-value 结构自定义缓存 CustomCache
205 1
C# 实现 key-value 结构自定义缓存 CustomCache
|
开发框架 JSON 前端开发
【C#】.net core2.1,自定义全局类对API接口和视图页面产生的异常统一处理
在开发一个网站项目时,异常处理和过滤功能是最基础的模块 本篇文章就来讲讲,如何自定义全局异常类来统一处理
248 0