Exportar (0) Imprimir
Expandir Tudo
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original

Graphics.BeginContainer Método

Saves a graphics container with the current state of this Graphics and opens and uses a new graphics container.

Namespace:  System.Drawing
Assembly:  System.Drawing (em System.Drawing. dll)

public GraphicsContainer BeginContainer()

Valor de retorno

Tipo: System.Drawing.Drawing2D.GraphicsContainer
This method returns a GraphicsContainer that represents the state of this Graphics at the time of the method call.

Use this method with the EndContainer method to create nested graphics containers.Recipientes gráficos retêm estado elementos gráficos, como transformação, região de corte e propriedades de processamento.

When you call the BeginContainer method of a Graphics, an information block that holds the state of the Graphics is put on a stack.The BeginContainer method returns a GraphicsContainer that identifies that information block.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.

Containers can be nested; that is, you can call the BeginContainer method several times before you call the EndContainer method.Each time you call the BeginContainer method, an information block is put on the stack, and you receive a GraphicsContainer for the information block.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.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.

Calls to the Save method place information blocks on the same stack as calls to the BeginContainer method.Just as an EndContainer method call is paired with a BeginContainer method call, a Restore method call is paired with a Save method call.

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.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.

The graphics state established by the BeginContainer method includes the rendering qualities of the default graphics state; any rendering-quality state changes existing when the method is called are reset to the default values.

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:

  • Abre um novo gráfico Contêiner e salva o antigo Contêiner.

  • Converte as coordenadas global na Contêiner.

  • Preenche um Retangular vermelho a (traduzido coordenadas da) Novo Contêiner.

  • Fecha a nova Contêiner e restaura o salva Contêiner.

  • Preenche um Retangular verde (para as coordenadas não traduzidos) da salvo Contêiner.

O resultado é um Retangular verde que overlies um Retangular vermelho do mesmo tamanho.

private void BeginContainerVoid(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);
}


Contribuições da comunidade

ADICIONAR
Mostrar:
© 2014 Microsoft