Graphics.EndContainer(GraphicsContainer) Método
Definição
Fecha o contêiner gráfico atual e restaura o estado deste Graphics para o estado salvo por uma chamada ao método BeginContainer().Closes the current graphics container and restores the state of this Graphics to the state saved by a call to the BeginContainer() method.
public:
void EndContainer(System::Drawing::Drawing2D::GraphicsContainer ^ container);
public void EndContainer (System.Drawing.Drawing2D.GraphicsContainer container);
member this.EndContainer : System.Drawing.Drawing2D.GraphicsContainer -> unit
Public Sub EndContainer (container As GraphicsContainer)
Parâmetros
- container
- GraphicsContainer
GraphicsContainer que representa o contêiner restaurado por esse método.GraphicsContainer that represents the container this method restores.
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:
Abre um novo contêiner de gráficos e salva o contêiner antigo.Opens a new graphics container and saves the old container.
Traduz as coordenadas mundiais no contêiner.Translates the world coordinates in the container.
Preenche um retângulo vermelho nas (coordenadas traduzidas do) novo contêiner.Fills a red rectangle in the (translated coordinates of the) new container.
Fecha o novo contêiner e restaura o contêiner salvo.Closes the new container and restores the saved container.
Preenche um retângulo verde (para as coordenadas não traduzidas) do contêiner salvo.Fills a green rectangle (to the untranslated coordinates) of the saved container.
O resultado é um retângulo verde que se baseia em um retângulo vermelho do mesmo tamanho.The result is a green rectangle that overlies a red rectangle of the same size.
public:
void EndContainerState( PaintEventArgs^ e )
{
// Begin graphics container.
GraphicsContainer^ containerState = e->Graphics->BeginContainer();
// Translate world transformation.
e->Graphics->TranslateTransform( 100.0F, 100.0F );
// Fill translated rectangle in container with red.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), 0, 0, 200, 200 );
// End graphics container.
e->Graphics->EndContainer( containerState );
// Fill untransformed rectangle with green.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Green ), 0, 0, 200, 200 );
}
public void EndContainerState(PaintEventArgs e)
{
// Begin graphics container.
GraphicsContainer containerState = e.Graphics.BeginContainer();
// Translate world transformation.
e.Graphics.TranslateTransform(100.0F, 100.0F);
// Fill translated rectangle in container with red.
e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200);
// End graphics container.
e.Graphics.EndContainer(containerState);
// Fill untransformed rectangle with green.
e.Graphics.FillRectangle(new SolidBrush(Color.Green), 0, 0, 200, 200);
}
Public Sub EndContainerState(ByVal e As PaintEventArgs)
' Begin graphics container.
Dim containerState As GraphicsContainer = _
e.Graphics.BeginContainer()
' Translate world transformation.
e.Graphics.TranslateTransform(100.0F, 100.0F)
' Fill translated rectangle in container with red.
e.Graphics.FillRectangle(New SolidBrush(Color.Red), 0, 0, _
200, 200)
' End graphics container.
e.Graphics.EndContainer(containerState)
' Fill untransformed rectangle with green.
e.Graphics.FillRectangle(New SolidBrush(Color.Green), 0, 0, _
200, 200)
End Sub
Comentários
Use esse método com o BeginContainer método para criar contêineres gráficos aninhados.Use this method with the BeginContainer method to create nested graphics containers. Os contêineres gráficos retêm o estado gráfico, como transformação, região de recorte e propriedades de renderização.Graphics containers retain graphics state, such as transformation, clipping region, and rendering properties.
Quando você chama o BeginContainer método de a Graphics , um bloco de informações que contém o estado de Graphics é colocado em uma pilha.When you call the BeginContainer method of a Graphics, an information block that holds the state of the Graphics is put on a stack. O BeginContainer método retorna um GraphicsContainer que identifica esse bloco de informações.The BeginContainer method returns a GraphicsContainer that identifies that information block. Quando você passa o objeto de identificação para o EndContainer método, o bloco de informações é removido da pilha e é usado para restaurar o Graphics para o estado em que ele estava no momento da BeginContainer chamada do método.When you pass the identifying object to the EndContainer method, the information block is removed from the stack and is used to restore the Graphics to the state it was in at the time of the BeginContainer method call.
Os contêineres podem ser aninhados; ou seja, você pode chamar o BeginContainer método várias vezes antes de chamar o EndContainer método.Containers can be nested; that is, you can call the BeginContainer method several times before you call the EndContainer method. Cada vez que você chama o BeginContainer método, um bloco de informações é colocado na pilha e você recebe um GraphicsContainer para o bloco de informações.Each time you call the BeginContainer method, an information block is put on the stack, and you receive a GraphicsContainer for the information block. Quando você passa um desses objetos para o EndContainer método, o Graphics é retornado para o estado em que ele estava no momento da chamada do BeginContainer método que retornou esse específico GraphicsContainer .When you pass one of those objects to the EndContainer method, the Graphics is returned to the state it was in at the time of the BeginContainer method call that returned that particular GraphicsContainer. O bloco de informações colocado na pilha por essa BeginContainer chamada de método é removido da pilha, e todos os blocos de informações colocados nessa pilha após essa BeginContainer chamada de método também são removidos.The information block placed on the stack by that BeginContainer method call is removed from the stack, and all information blocks placed on that stack after that BeginContainer method call are also removed.
Chamadas para o Save método colocam os blocos de informações na mesma pilha como chamadas para o BeginContainer método.Calls to the Save method place information blocks on the same stack as calls to the BeginContainer method. Assim como uma EndContainer chamada de método é emparelhada com uma BeginContainer chamada de método, uma chamada de método Restore é emparelhada com uma Save chamada de método.Just as an EndContainer method call is paired with a BeginContainer method call, a Restore method call is paired with a Save method call.
Quando você chama o EndContainer método, todos os blocos de informações colocados na pilha (pelo Save método ou pelo BeginContainer método) após a chamada correspondente para o BeginContainer método são removidos da pilha.When you call the EndContainer method, all information blocks placed on the stack (by the Save method or by the BeginContainer method) after the corresponding call to the BeginContainer method are removed from the stack. Da mesma forma, quando você chama o Restore método, todos os blocos de informações colocados na pilha (pelo Save método ou pelo BeginContainer método) após a chamada correspondente para o Save método são removidos da pilha.Likewise, when you call the Restore method, all information blocks placed on the stack (by the Save method or by the BeginContainer method) after the corresponding call to the Save method are removed from the stack.