RegionData 类
封装构成 Region 对象的数据。无法继承此类。
**命名空间:**System.Drawing.Drawing2D
**程序集:**System.Drawing(在 system.drawing.dll 中)
语法
声明
Public NotInheritable Class RegionData
用法
Dim instance As RegionData
public sealed class RegionData
public ref class RegionData sealed
public final class RegionData
public final class RegionData
示例
下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgse(这是 Paint 事件处理程序的参数)。代码执行下列操作:
创建一个矩形并用黑色将其绘制到屏幕。
使用该矩形创建一个区域。
获取 RegionData。
通过使用 DisplayRegionData Helper 功能,将区域数据(字节的数组)绘制到屏幕上。
Public Sub GetRegionDataExample(ByVal e As PaintEventArgs)
' Create the first rectangle and draw it to the screen in black.
Dim regionRect As New Rectangle(20, 20, 100, 100)
e.Graphics.DrawRectangle(Pens.Black, regionRect)
' Create a region using the first rectangle.
Dim myRegion As New [Region](regionRect)
' Get the RegionData for this region.
Dim myRegionData As RegionData = myRegion.GetRegionData()
Dim myRegionDataLength As Integer = myRegionData.Data.Length
DisplayRegionData(e, myRegionDataLength, myRegionData)
End Sub
' Helper Function for GetRegionData.
Public Sub DisplayRegionData(ByVal e As PaintEventArgs, ByVal len As Integer, _
ByVal dat As RegionData)
' Display the result.
Dim i As Integer
Dim x As Single = 20
Dim y As Single = 140
Dim myFont As New Font("Arial", 8)
Dim myBrush As New SolidBrush(Color.Black)
e.Graphics.DrawString("myRegionData = ", myFont, myBrush, _
New PointF(x, y))
y = 160
For i = 0 To len - 1
If x > 300 Then
y += 20
x = 20
End If
e.Graphics.DrawString(dat.Data(i).ToString(), myFont, _
myBrush, New PointF(x, y))
x += 30
Next i
End Sub
public void GetRegionDataExample(PaintEventArgs e)
{
// Create a rectangle and draw it to the screen in black.
Rectangle regionRect = new Rectangle(20, 20, 100, 100);
e.Graphics.DrawRectangle(Pens.Black, regionRect);
// Create a region using the first rectangle.
Region myRegion = new Region(regionRect);
// Get the RegionData for this region.
RegionData myRegionData = myRegion.GetRegionData();
int myRegionDataLength = myRegionData.Data.Length;
DisplayRegionData(e, myRegionDataLength, myRegionData);
}
// THIS IS A HELPER FUNCTION FOR GetRegionData.
public void DisplayRegionData(PaintEventArgs e,
int len,
RegionData dat)
{
// Display the result.
int i;
float x = 20, y = 140;
Font myFont = new Font("Arial", 8);
SolidBrush myBrush = new SolidBrush(Color.Black);
e.Graphics.DrawString("myRegionData = ",
myFont,
myBrush,
new PointF(x, y));
y = 160;
for(i = 0; i < len; i++)
{
if(x > 300)
{
y += 20;
x = 20;
}
e.Graphics.DrawString(dat.Data[i].ToString(),
myFont,
myBrush,
new PointF(x, y));
x += 30;
}
}
public:
void GetRegionDataExample( PaintEventArgs^ e )
{
// Create a rectangle and draw it to the screen in black.
Rectangle regionRect = Rectangle(20,20,100,100);
e->Graphics->DrawRectangle( Pens::Black, regionRect );
// Create a region using the first rectangle.
System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect );
// Get the RegionData for this region.
RegionData^ myRegionData = myRegion->GetRegionData();
int myRegionDataLength = myRegionData->Data->Length;
DisplayRegionData( e, myRegionDataLength, myRegionData );
}
// THIS IS A HELPER FUNCTION FOR GetRegionData.
void DisplayRegionData( PaintEventArgs^ e, int len, RegionData^ dat )
{
// Display the result.
int i;
float x = 20,y = 140;
System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Arial",8 );
SolidBrush^ myBrush = gcnew SolidBrush( Color::Black );
e->Graphics->DrawString( "myRegionData = ", myFont, myBrush, PointF(x,y) );
y = 160;
for ( i = 0; i < len; i++ )
{
if ( x > 300 )
{
y += 20;
x = 20;
}
e->Graphics->DrawString( dat->Data[ i ].ToString(), myFont, myBrush, PointF(x,y) );
x += 30;
}
}
public void GetRegionDataExample(PaintEventArgs e)
{
// Create a rectangle and draw it to the screen in black.
Rectangle regionRect = new Rectangle(20, 20, 100, 100);
e.get_Graphics().DrawRectangle(Pens.get_Black(), regionRect);
// Create a region using the first rectangle.
Region myRegion = new Region(regionRect);
// Get the RegionData for this region.
RegionData myRegionData = myRegion.GetRegionData();
int myRegionDataLength = myRegionData.get_Data().length;
DisplayRegionData(e, myRegionDataLength, myRegionData);
} //GetRegionDataExample
// THIS IS A HELPER FUNCTION FOR GetRegionData.
public void DisplayRegionData(PaintEventArgs e, int len, RegionData dat)
{
// Display the result.
int i;
float x = 20;
float y = 140;
Font myFont = new Font("Arial", 8);
SolidBrush myBrush = new SolidBrush(Color.get_Black());
e.get_Graphics().DrawString("myRegionData = ", myFont, myBrush,
new PointF(x, y));
y = 160;
for (i = 0; i < len; i++) {
if (x > 300) {
y += 20;
x = 20;
}
e.get_Graphics().DrawString(dat.get_Data().get_Item(i).ToString(),
myFont, myBrush, new PointF(x, y));
x += 30;
}
} //DisplayRegionData
继承层次结构
System.Object
System.Drawing.Drawing2D.RegionData
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0