Region.Exclude Metodo

Definizione

Aggiorna questa classe Region alla sezione della parte interna che non interseca la struttura Rectangle specificata.

Overload

Exclude(Region)

Aggiorna questa classe Region in modo che contenga solo la sezione della parte interna che non interseca la classe Region specificata.

Exclude(GraphicsPath)

Aggiorna questa classe Region in modo che contenga solo la sezione della parte interna che non interseca la classe GraphicsPath specificata.

Exclude(Rectangle)

Aggiorna questa classe Region in modo che contenga solo la sezione della parte interna che non interseca la struttura Rectangle specificata.

Exclude(RectangleF)

Aggiorna questa classe Region in modo che contenga solo la sezione della parte interna che non interseca la struttura RectangleF specificata.

Exclude(Region)

Aggiorna questa classe Region in modo che contenga solo la sezione della parte interna che non interseca la classe Region specificata.

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)

Parametri

region
Region

Classe Region da escludere da questa classe Region.

Eccezioni

region è null.

Esempio

Per esempi di codice, vedere i Exclude(RectangleF) metodi e Complement(Region) .

Si applica a

Exclude(GraphicsPath)

Aggiorna questa classe Region in modo che contenga solo la sezione della parte interna che non interseca la classe GraphicsPath specificata.

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)

Parametri

path
GraphicsPath

Classe GraphicsPath da escludere da questa classe Region.

Eccezioni

path è null.

Esempio

Nell'esempio di codice seguente viene illustrato il Region costruttore e i Exclude metodi e Dispose .

Questo esempio è progettato per essere usato con Windows Forms. Incollare il codice in una maschera e chiamare il metodo quando si gestisce l'evento FillRegionExcludingPath del Paint modulo, passando e come 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

Si applica a

Exclude(Rectangle)

Aggiorna questa classe Region in modo che contenga solo la sezione della parte interna che non interseca la struttura Rectangle specificata.

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)

Parametri

rect
Rectangle

Struttura Rectangle da escludere da questa classe Region.

Esempio

Per un esempio di codice, vedere il Exclude(RectangleF) metodo .

Si applica a

Exclude(RectangleF)

Aggiorna questa classe Region in modo che contenga solo la sezione della parte interna che non interseca la struttura RectangleF specificata.

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)

Parametri

rect
RectangleF

Struttura RectangleF da escludere da questa classe Region.

Esempio

L'esempio seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea un rettangolo e lo disegna sullo schermo in nero

  • Crea un secondo rettangolo che interseca con il primo e lo disegna sullo schermo in rosso.

  • Crea un'area usando il primo rettangolo.

  • Ottiene l'area non isolata dell'area in combinazione con il secondo rettangolo.

  • Riempie l'area non isolata con blu e lo disegna sullo schermo.

Si noti che l'area dell'area che non si interseca con il rettangolo è di colore blu.

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

Si applica a