C# GDI+简单绘图演示

本文介绍使用C# Windows Forms应用程序绘制不同类型的图形,并演示如何应用各种填充效果,包括纯色、图案填充及线性渐变等。通过按钮触发不同的绘图操作,如矩形填充、图案填充、线性渐变填充、直线绘制以及扇形绘制。

就是算坐标要仔细,要不然,就不知道图画到哪里去了。。。

还好,我几何学得不太差。。将六个图合到一个大图,算得出来。。。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 using System.Drawing.Drawing2D;
11 
12 namespace WindowsFormsApplication3
13 {
14     public partial class Form1 : Form
15     {
16         public Form1()
17         {
18             InitializeComponent();
19         }
20 
21         private void button1_Click(object sender, EventArgs e)
22         {
23             Graphics ghs = this.CreateGraphics();
24             Brush mybs = new SolidBrush(Color.Red);
25             Rectangle rt = new Rectangle(12, 40, 100, 100);
26             ghs.FillRectangle(mybs, rt);
27         }
28 
29         private void button2_Click(object sender, EventArgs e)
30         {
31             Graphics ghs = this.CreateGraphics();
32             for (int i = 1; i < 6; i++)
33             {
34                 HatchStyle hs = (HatchStyle)(5 + i);
35                 HatchBrush hb = new HatchBrush(hs, Color.Blue);
36                 Rectangle rtl = new Rectangle(175, 30 * i, 30 * i, 50);
37                 ghs.FillRectangle(hb, rtl);
38             }
39         }
40 
41         private void button3_Click(object sender, EventArgs e)
42         {
43             Point p1 = new Point(300, 30);
44             Point p2 = new Point(350, 50);
45             LinearGradientBrush lgb = new LinearGradientBrush(p1, p2, Color.Brown, Color.Cyan);
46             Graphics ghs = this.CreateGraphics();
47             lgb.WrapMode = WrapMode.TileFlipX;
48             ghs.FillRectangle(lgb, 320, 50, 100, 100);
49         }
50 
51         private void button4_Click(object sender, EventArgs e)
52         {
53             Pen blackPen = new Pen(Color.Black, 3);
54             Point point1 = new Point(12, 300);
55             Point point2 = new Point(100, 300);
56             Graphics g = this.CreateGraphics();
57             g.DrawLine(blackPen, point1, point2);
58         }
59 
60         private void button5_Click(object sender, EventArgs e)
61         {
62             Graphics graphics = this.CreateGraphics();
63             Pen myPen = new Pen(Color.Black, 3);
64             Point point1 = new Point(220, 270);
65             Point point2 = new Point(220, 350);
66             graphics.DrawLine(myPen, point1, point2);
67         }
68 
69         private void button6_Click(object sender, EventArgs e)
70         {
71             Graphics ghs = this.CreateGraphics();
72             Pen myPen = new Pen(Color.Orange, 3);
73             ghs.DrawPie(myPen,300,300,120,100, 210,120);
74         }
75     }
76 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值