Region.GetBounds(Graphics) Methode

Definition

Ruft eine RectangleF-Struktur ab, die ein Rechteck darstellt, das diese Region auf der Zeichenoberfläche eines Graphics-Objekts begrenzt.

public:
 System::Drawing::RectangleF GetBounds(System::Drawing::Graphics ^ g);
public System.Drawing.RectangleF GetBounds (System.Drawing.Graphics g);
member this.GetBounds : System.Drawing.Graphics -> System.Drawing.RectangleF
Public Function GetBounds (g As Graphics) As RectangleF

Parameter

g
Graphics

Das Graphics, auf dem diese Region gezeichnet wird.

Gibt zurück

RectangleF

Eine RectangleF-Struktur, die das umschließende Rechteck für diese Region auf der angegebenen Zeichenoberfläche darstellt.

Ausnahmen

g ist null.

Beispiele

Das folgende Codebeispiel wurde für die Verwendung mit Windows Forms entwickelt und erfordert PaintEventArgs eeinen Parameter des Paint Ereignishandlers. Der Code führt die folgenden Aktionen aus:

  • Erstellt ein GraphicsPath Auslassungspunkte und fügt ihn hinzu.

  • Füllt den Pfad mit Blau aus und zeichnet ihn auf den Bildschirm.

  • Erstellt einen Bereich, der die GraphicsPath.

  • Ruft den nicht eingeschlossenen Bereich des Bereichs ab, wenn er mit dem zweiten Rechteck kombiniert wird.

  • Ruft das umgebende Rechteck für den Bereich ab und zeichnet es in Rot auf den Bildschirm.

public:
   void GetBoundsExample( PaintEventArgs^ e )
   {
      // Create a GraphicsPath and add an ellipse to it.
      GraphicsPath^ myPath = gcnew GraphicsPath;
      Rectangle ellipseRect = Rectangle(20,20,100,100);
      myPath->AddEllipse( ellipseRect );

      // Fill the path with blue and draw it to the screen.
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
      e->Graphics->FillPath( myBrush, myPath );

      // Create a region using the GraphicsPath.
      System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( myPath );

      // Get the bounding rectangle for myRegion and draw it to the
      // screen in Red.
      RectangleF boundsRect = myRegion->GetBounds( e->Graphics );
      e->Graphics->DrawRectangle( Pens::Red, Rectangle::Round( boundsRect ) );
   }
public void GetBoundsExample(PaintEventArgs e)
{
             
    // Create a GraphicsPath and add an ellipse to it.
    GraphicsPath myPath = new GraphicsPath();
    Rectangle ellipseRect = new Rectangle(20, 20, 100, 100);
    myPath.AddEllipse(ellipseRect);
             
    // Fill the path with blue and draw it to the screen.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillPath(myBrush, myPath);
             
    // Create a region using the GraphicsPath.
    Region myRegion = new Region(myPath);
             
    // Get the bounding rectangle for myRegion and draw it to the
             
    // screen in Red.
    RectangleF boundsRect = myRegion.GetBounds(e.Graphics);
    e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect));
}
Public Sub GetBoundsExample(ByVal e As PaintEventArgs)

    ' Create a GraphicsPath and add an ellipse to it.
    Dim myPath As New GraphicsPath
    Dim ellipseRect As New Rectangle(20, 20, 100, 100)
    myPath.AddEllipse(ellipseRect)

    ' Fill the path with blue and draw it to the screen.
    Dim myBrush As New SolidBrush(Color.Blue)
    e.Graphics.FillPath(myBrush, myPath)

    ' Create a region using the GraphicsPath.
    Dim myRegion As New [Region](myPath)

    ' Get the bounding rectangle for myRegion and draw it to the
    ' screen in Red.
    Dim boundsRect As RectangleF = myRegion.GetBounds(e.Graphics)
    e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect))
End Sub

Hinweise

Die aktuelle Transformation des Grafikkontexts wird verwendet, um den Bereich innen auf der Zeichnungsoberfläche zu berechnen. Das umgebende Rechteck ist je nach der aktuellen Transformation nicht immer das kleinste begrenzungsgebundene Rechteck.

Gilt für: