Teilen über


Region.GetBounds(Graphics) Methode

Definition

Ruft eine RectangleF Struktur, die ein Rechteck darstellt, das diese Region auf der Zeichnungsoberflä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

Die Graphics, auf die diese Region gezeichnet wird.

Gibt zurück

Eine RectangleF Struktur, die das umgebende Rechteck für dieses Region auf der angegebenen Zeichnungsoberfläche darstellt.

Ausnahmen

g ist null.

Beispiele

Das folgende Codebeispiel wurde für die Verwendung mit Windows Forms entwickelt und erfordert PaintEventArgse, bei dem es sich um einen Parameter des Paint-Ereignishandlers handelt. Der Code führt die folgenden Aktionen aus:

  • Erstellt eine GraphicsPath und fügt ihr eine Auslassungspunkte hinzu.

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

  • Erstellt einen Bereich, der die GraphicsPathverwendet.

  • 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 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 Innenbereich auf der Zeichnungsoberfläche zu berechnen. Das umgebende Rechteck ist je nach der aktuellen Transformation nicht immer das kleinste begrenzungsgebundene Rechteck.

Gilt für: