Region.Exclude 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
Exclude(Region) | |
Exclude(GraphicsPath) |
更新此 Region 以仅包含其内部不与指定 GraphicsPath相交的部分。 |
Exclude(Rectangle) | |
Exclude(RectangleF) |
更新此 Region 以仅包含与指定 RectangleF 结构不相交的内部部分。 |
Exclude(Region)
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
public:
void Exclude(System::Drawing::Region ^ region);
public void Exclude (System.Drawing.Region region);
member this.Exclude : System.Drawing.Region -> unit
Public Sub Exclude (region As Region)
参数
例外
region
null
。
示例
有关代码示例,请参阅 Exclude(RectangleF) 和 Complement(Region) 方法。
适用于
Exclude(GraphicsPath)
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
更新此 Region 以仅包含其内部不与指定 GraphicsPath相交的部分。
public:
void Exclude(System::Drawing::Drawing2D::GraphicsPath ^ path);
public void Exclude (System.Drawing.Drawing2D.GraphicsPath path);
member this.Exclude : System.Drawing.Drawing2D.GraphicsPath -> unit
Public Sub Exclude (path As GraphicsPath)
参数
- path
- GraphicsPath
要从此 Region中排除的 GraphicsPath。
例外
path
null
。
示例
下面的代码示例演示 Region 构造函数和 Exclude 和 Dispose 方法。
此示例旨在与 Windows 窗体一起使用。 将代码粘贴到窗体中,并在处理表单的 Paint 事件时调用 FillRegionExcludingPath
方法,并将 e
作为 PaintEventArgs传递。
private:
void FillRegionExcludingPath( PaintEventArgs^ e )
{
// Create the region using a rectangle.
System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( Rectangle(20,20,100,100) );
// Create the GraphicsPath.
System::Drawing::Drawing2D::GraphicsPath^ path = gcnew System::Drawing::Drawing2D::GraphicsPath;
// Add a circle to the graphics path.
path->AddEllipse( 50, 50, 25, 25 );
// Exclude the circle from the region.
myRegion->Exclude( path );
// Retrieve a Graphics object from the form.
Graphics^ formGraphics = e->Graphics;
// Fill the region in blue.
formGraphics->FillRegion( Brushes::Blue, myRegion );
// Dispose of the path and region objects.
delete path;
delete myRegion;
}
private void FillRegionExcludingPath(PaintEventArgs e)
{
// Create the region using a rectangle.
Region myRegion = new Region(new Rectangle(20, 20, 100, 100));
// Create the GraphicsPath.
System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath();
// Add a circle to the graphics path.
path.AddEllipse(50, 50, 25, 25);
// Exclude the circle from the region.
myRegion.Exclude(path);
// Retrieve a Graphics object from the form.
Graphics formGraphics = e.Graphics;
// Fill the region in blue.
formGraphics.FillRegion(Brushes.Blue, myRegion);
// Dispose of the path and region objects.
path.Dispose();
myRegion.Dispose();
}
Private Sub FillRegionExcludingPath(ByVal e As PaintEventArgs)
' Create the region using a rectangle.
Dim myRegion As New Region(New Rectangle(20, 20, 100, 100))
' Create the GraphicsPath.
Dim path As New System.Drawing.Drawing2D.GraphicsPath
' Add a circle to the graphics path.
path.AddEllipse(50, 50, 25, 25)
' Exclude the circle from the region.
myRegion.Exclude(path)
' Retrieve a Graphics object from the form.
Dim formGraphics As Graphics = e.Graphics
' Fill the region in blue.
formGraphics.FillRegion(Brushes.Blue, myRegion)
' Dispose of the path and region objects.
path.Dispose()
myRegion.Dispose()
End Sub
适用于
Exclude(Rectangle)
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
public:
void Exclude(System::Drawing::Rectangle rect);
public void Exclude (System.Drawing.Rectangle rect);
member this.Exclude : System.Drawing.Rectangle -> unit
Public Sub Exclude (rect As Rectangle)
参数
示例
有关代码示例,请参阅 Exclude(RectangleF) 方法。
适用于
Exclude(RectangleF)
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
更新此 Region 以仅包含与指定 RectangleF 结构不相交的内部部分。
public:
void Exclude(System::Drawing::RectangleF rect);
public void Exclude (System.Drawing.RectangleF rect);
member this.Exclude : System.Drawing.RectangleF -> unit
Public Sub Exclude (rect As RectangleF)
参数
- rect
- RectangleF
要从此 Region中排除的 RectangleF 结构。
示例
下面的示例设计用于 Windows 窗体,它需要 PaintEventArgse
,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
创建一个矩形并将其绘制到黑色屏幕
创建第二个矩形,该矩形与第一个矩形相交,并用红色将其绘制到屏幕。
使用第一个矩形创建区域。
当与第二个矩形组合时,获取区域的非excluded 区域。
用蓝色填充非封闭区域,并将其绘制到屏幕。
请注意,不与矩形相交的区域的区域的颜色为蓝色。
public:
void Exclude_RectF_Example( PaintEventArgs^ e )
{
// Create the first rectangle and draw it to the screen in black.
Rectangle regionRect = Rectangle(20,20,100,100);
e->Graphics->DrawRectangle( Pens::Black, regionRect );
// Create the second rectangle and draw it to the screen in red.
RectangleF complementRect = RectangleF(90,30,100,100);
e->Graphics->DrawRectangle( Pens::Red, Rectangle::Round( complementRect ) );
// Create a region using the first rectangle.
System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect );
// Get the nonexcluded area of myRegion when combined with
// complementRect.
myRegion->Exclude( complementRect );
// Fill the nonexcluded area of myRegion with blue.
SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
e->Graphics->FillRegion( myBrush, myRegion );
}
public void Exclude_RectF_Example(PaintEventArgs e)
{
// Create the first rectangle and draw it to the screen in black.
Rectangle regionRect = new Rectangle(20, 20, 100, 100);
e.Graphics.DrawRectangle(Pens.Black, regionRect);
// Create the second rectangle and draw it to the screen in red.
RectangleF complementRect = new RectangleF(90, 30, 100, 100);
e.Graphics.DrawRectangle(Pens.Red,
Rectangle.Round(complementRect));
// Create a region using the first rectangle.
Region myRegion = new Region(regionRect);
// Get the nonexcluded area of myRegion when combined with
// complementRect.
myRegion.Exclude(complementRect);
// Fill the nonexcluded area of myRegion with blue.
SolidBrush myBrush = new SolidBrush(Color.Blue);
e.Graphics.FillRegion(myBrush, myRegion);
}
Public Sub Exclude_RectF_Example(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 the second rectangle and draw it to the screen in red.
Dim complementRect As New RectangleF(90, 30, 100, 100)
e.Graphics.DrawRectangle(Pens.Red, _
Rectangle.Round(complementRect))
' Create a region using the first rectangle.
Dim myRegion As New [Region](regionRect)
' Get the nonexcluded area of myRegion when combined with
' complementRect.
myRegion.Exclude(complementRect)
' Fill the nonexcluded area of myRegion with blue.
Dim myBrush As New SolidBrush(Color.Blue)
e.Graphics.FillRegion(myBrush, myRegion)
End Sub