Region.GetBounds(Graphics) Método
Definição
Obtém uma estrutura RectangleF que representa um retângulo que delimita este Region na superfície de desenho de um objeto Graphics.Gets a RectangleF structure that represents a rectangle that bounds this Region on the drawing surface of a Graphics object.
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
Retornos
A estrutura RectangleF que representa o retângulo delimitador para este Region na superfície de desenho especificada.A RectangleF structure that represents the bounding rectangle for this Region on the specified drawing surface.
Exceções
g é null.g is null.
Exemplos
O exemplo de código a seguir foi projetado para uso com Windows Forms, e ele requer PaintEventArgs e , que é um parâmetro do Paint manipulador de eventos.The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. O código executa as seguintes ações:The code performs the following actions:
Cria um GraphicsPath e adiciona uma elipse a ele.Creates a GraphicsPath and adds an ellipse to it.
Preenche o caminho com azul e o desenha na tela.Fills the path with blue and draws it to the screen.
Cria uma região que usa o GraphicsPath .Creates a region that uses the GraphicsPath.
Obtém a área não excluída da região quando combinada com o segundo retângulo.Gets the nonexcluded area of the region when combined with the second rectangle.
Obtém o retângulo delimitador para a região e o desenha na tela em vermelho.Gets the bounding rectangle for the region and draws it to the screen in red.
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
Comentários
A transformação atual do contexto de gráficos é usada para calcular a região interior na superfície de desenho.The current transformation of the graphics context is used to compute the region interior on the drawing surface. O retângulo delimitador nem sempre é o menor retângulo delimitador possível dependendo da transformação atual.The bounding rectangle is not always the smallest possible bounding rectangle depending on the current transformation.