using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace 区域
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
/**
//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
/**
//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components =
null;
public Form1()
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
//
// Windows 窗体设计器支持所必需的
// ![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
// ![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
/**
//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose(
bool disposing )
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
if( disposing )
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
if (components !=
null)
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
components.Dispose();
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
base.Dispose( disposing );
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
Windows Form Designer generated code
#region Windows Form Designer generated code
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
/**
//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
//
// Form1
//
this.AutoScaleBaseSize =
new System.Drawing.Size(6, 14);
this.ClientSize =
new System.Drawing.Size(632, 526);
this.Name =
"Form1";
this.Text =
"区域";
this.Load +=
new System.EventHandler(
this.Form1_Load);
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
#endregion
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
/**
//// <summary>
/// 应用程序的主入口点。
/// </summary> ![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
[STAThread]
static void Main()
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
Application.Run(
new Form1());
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
protected override void OnPaint(PaintEventArgs e)
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
Graphics g= e.Graphics;
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
g.FillRectangle(Brushes.White,
this.ClientRectangle);
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
Region r1=
new Region(
new RectangleF(60, 50, 150, 100));
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
GraphicsPath gp=
new GraphicsPath();
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
gp.AddLine(300, 50, 500, 100);
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
gp.AddLine(500, 100, 400, 200);
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
gp.CloseFigure();
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
gp.StartFigure();
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
gp.AddEllipse(50, 200, 200, 100);
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
Region r2=
new Region(gp);
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
g.FillRegion(Brushes.CornflowerBlue, r1);
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
g.FillRegion(Brushes.DarkOrange, r2);
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
r1.Dispose();
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
r2.Dispose();
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
gp.Dispose();
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
private void Form1_Load(
object sender, System.EventArgs e)
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
...{
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}
![GDI+中区域的定义和绘制_GDI+](https://s2.51cto.com/images/editer/InBlock.gif)
}