GDI+绘图
1
using System;
2
using System.Drawing;
3
using System.Collections;
4
using System.ComponentModel;
5
using System.Windows.Forms;
6
using System.Data;
7![]()
8
namespace GDIDrawing
9
{
10
/// <summary>
11
/// GDI+绘图。
12
/// </summary>
13
public class Form1 : System.Windows.Forms.Form
14
{
15
/// <summary>
16
/// 必需的设计器变量。
17
/// </summary>
18
private System.ComponentModel.Container components = null;
19![]()
20
public Form1()
21
{
22
// Windows 窗体设计器支持所必需的
23
InitializeComponent();
24
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
25
}
26![]()
27
/// <summary>
28
/// 清理所有正在使用的资源。
29
/// </summary>
30
protected override void Dispose( bool disposing )
31
{
32
if( disposing )
33
{
34
if (components != null)
35
{
36
components.Dispose();
37
}
38
}
39
base.Dispose( disposing );
40
}
41![]()
42
Windows Form Designer generated code
63![]()
64
/// <summary>
65
/// 应用程序的主入口点。
66
/// </summary>
67
[STAThread]
68
static void Main()
69
{
70
Application.Run(new Form1());
71
}
72
// 进行基本的GDI+绘图操作。
73
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
74
{
75
Graphics g = e.Graphics;
76
g.Clear(this.BackColor);
77
g.DrawLine(new Pen(Color.Blue, 5.0f), 20, 20, 200, 20);
78
g.DrawRectangle(new Pen(Color.DarkCyan, 3.0f), 20, 50, 300, 80);
79
Point[] points =
80
{
81
new Point( 100, 10),
82
new Point( 10, 100),
83
new Point(300, 50),
84
new Point(230, 120),
85
new Point(100, 220),
86
new Point(this.Width/2,this.Height/2),
87
new Point(0, 300)
88
};
89
g.DrawLines(new Pen(Color.DarkGreen, 4.0f), points);
90
RectangleF[] rects =
91
{
92
new RectangleF( 0.0F, 0.0F, 100.0F, 200.0F),
93
new RectangleF(100.0F, 200.0F, 250.0F, 50.0F),
94
new RectangleF(300.0F, 0.0F, 50.0F, 100.0F)
95
};
96
g.DrawRectangles(new Pen(Color.DarkGreen, 5.0f), rects);
97
}
98
}
99
}
100![]()
using System;2
using System.Drawing;3
using System.Collections;4
using System.ComponentModel;5
using System.Windows.Forms;6
using System.Data;7

8
namespace GDIDrawing9
{10
/// <summary>11
/// GDI+绘图。12
/// </summary>13
public class Form1 : System.Windows.Forms.Form14
{15
/// <summary>16
/// 必需的设计器变量。17
/// </summary>18
private System.ComponentModel.Container components = null;19

20
public Form1()21
{22
// Windows 窗体设计器支持所必需的23
InitializeComponent();24
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码25
}26

27
/// <summary>28
/// 清理所有正在使用的资源。29
/// </summary>30
protected override void Dispose( bool disposing )31
{32
if( disposing )33
{34
if (components != null) 35
{36
components.Dispose();37
}38
}39
base.Dispose( disposing );40
}41

42
Windows Form Designer generated code63

64
/// <summary>65
/// 应用程序的主入口点。66
/// </summary>67
[STAThread]68
static void Main() 69
{70
Application.Run(new Form1());71
}72
// 进行基本的GDI+绘图操作。73
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)74
{75
Graphics g = e.Graphics;76
g.Clear(this.BackColor);77
g.DrawLine(new Pen(Color.Blue, 5.0f), 20, 20, 200, 20);78
g.DrawRectangle(new Pen(Color.DarkCyan, 3.0f), 20, 50, 300, 80);79
Point[] points =80
{81
new Point( 100, 10),82
new Point( 10, 100),83
new Point(300, 50),84
new Point(230, 120),85
new Point(100, 220),86
new Point(this.Width/2,this.Height/2),87
new Point(0, 300)88
};89
g.DrawLines(new Pen(Color.DarkGreen, 4.0f), points);90
RectangleF[] rects =91
{92
new RectangleF( 0.0F, 0.0F, 100.0F, 200.0F),93
new RectangleF(100.0F, 200.0F, 250.0F, 50.0F),94
new RectangleF(300.0F, 0.0F, 50.0F, 100.0F)95
};96
g.DrawRectangles(new Pen(Color.DarkGreen, 5.0f), rects);97
}98
}99
}100



浙公网安备 33010602011771号