Region.Exclude 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
Exclude(Region) | |
Exclude(GraphicsPath) |
更新此 Region,只包含其內部部分,但未與指定的 GraphicsPath相交。 |
Exclude(Rectangle) | |
Exclude(RectangleF) |
更新此 Region,只包含其內部與指定之 RectangleF 結構不相交的部分。 |
Exclude(Region)
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- 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)
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- 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 Forms 搭配使用。 將程式代碼貼到表單中,並在處理表單的 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)
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- 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)
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- Region.cs
- 來源:
- 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 Forms 搭配使用,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
建立矩形,並將它繪製到黑色的畫面
建立第二個矩形,與第一個矩形交集,並以紅色繪製到畫面。
使用第一個矩形建立區域。
當與第二個矩形結合時,取得區域的非排除區域。
以藍色填滿非隔離區域,並將它繪製到螢幕。
請注意,未與矩形交集的區域區域會以藍色表示。
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