Region.GetBounds(Graphics) Método

Definición

Obtiene una estructura RectangleF que representa un rectángulo que delimita esta Region en la superficie de dibujo de un objeto Graphics.

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

Parámetros

g
Graphics

Graphics en el que se dibuja esta Region.

Devoluciones

Una estructura RectangleF que representa el rectángulo delimitador de esta Region en la superficie de dibujo especificada.

Excepciones

Ejemplos

El ejemplo de código siguiente está diseñado para su uso con Windows Forms y requiere PaintEventArgse, que es un parámetro del Paint controlador de eventos. El código realiza las siguientes acciones:

  • Crea un GraphicsPath objeto y agrega una elipse a él.

  • Rellena el camino con azul y lo dibuja en la pantalla.

  • Crea una región que usa .GraphicsPath

  • Obtiene el área no aislada de la región cuando se combina con el segundo rectángulo.

  • Obtiene el rectángulo delimitador de la región y lo dibuja en la pantalla en rojo.

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

Comentarios

La transformación actual del contexto de gráficos se usa para calcular el interior de la región en la superficie de dibujo. El rectángulo delimitador no siempre es el rectángulo delimitador más pequeño posible en función de la transformación actual.

Se aplica a