Region.GetBounds(Graphics) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém-se uma RectangleF estrutura que representa um retângulo que limita este Region na superfície de desenho de um Graphics objeto.
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
Devoluções
Uma RectangleF estrutura que representa o retângulo delimitador para isto Region na superfície de desenho especificada.
Exceções
g é null.
Exemplos
O seguinte exemplo de código foi concebido para uso com Windows Forms e requer PaintEventArgse, que é um parâmetro do tratador de eventos Paint. O código executa as seguintes ações:
Cria um GraphicsPath e acrescenta uma elipse a ele.
Preenche o caminho com azul e desenha-o para o ecrã.
Cria uma região que utiliza o GraphicsPath.
Obtém a área não excluída da região quando combinada com o segundo retângulo.
Recebe o retângulo delimitador da região e desenha-o para o ecrã em vermelho.
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
Observações
A transformação atual do contexto gráfico é usada para calcular o interior da região na superfície de desenho. O retângulo delimitador nem sempre é o menor retângulo delimitador possível, dependendo da transformação atual.