Como: Criar figuras de linhas, curvas e formas

Para criar uma figura, construir um GraphicsPathe chamar métodos, sistema autônomo AddLine e AddCurve, para adicionar o caminho de primitivos.

Exemplo

Os exemplos de código a seguir criar caminhos que possuem figuras:

  • O primeiro exemplo cria um caminho que tenha uma única figura.A Figura consiste em um único arco.O arco tem um ângulo de varredura de – 180 graus, no sentido anti-horário no sistema de coordenada padrão.

  • O segundo exemplo cria um caminho que tem dois valores.A Figura primeira é um arco seguido por uma linha.A figura a segunda é uma linha seguida de uma curva seguida por uma linha.O primeiro número for deixado em aberto e a segunda figura é fechada.

Dim path As New GraphicsPath()
path.AddArc(175, 50, 50, 50, 0, -180)
e.Graphics.DrawPath(New Pen(Color.FromArgb(128, 255, 0, 0), 4), path)

GraphicsPath path = new GraphicsPath();
path.AddArc(175, 50, 50, 50, 0, -180);
e.Graphics.DrawPath(new Pen(Color.FromArgb(128, 255, 0, 0), 4), path);
' Create an array of points for the curve in the second figure.
Dim points As Point() = { _
   New Point(40, 60), _
   New Point(50, 70), _
   New Point(30, 90)}

Dim path As New GraphicsPath()

path.StartFigure() ' Start the first figure.
path.AddArc(175, 50, 50, 50, 0, -180)
path.AddLine(100, 0, 250, 20)
' First figure is not closed.

path.StartFigure() ' Start the second figure.
path.AddLine(50, 20, 5, 90)
path.AddCurve(points, 3)
path.AddLine(50, 150, 150, 180)
path.CloseFigure() ' Second figure is closed.
e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 0, 0), 2), path)

     // Create an array of points for the curve in the second figure.
     Point[] points = {
new Point(40, 60),
new Point(50, 70),
new Point(30, 90)};

     GraphicsPath path = new GraphicsPath();

     path.StartFigure(); // Start the first figure.
     path.AddArc(175, 50, 50, 50, 0, -180);
     path.AddLine(100, 0, 250, 20);
     // First figure is not closed.

     path.StartFigure(); // Start the second figure.
     path.AddLine(50, 20, 5, 90);
     path.AddCurve(points, 3);
     path.AddLine(50, 150, 150, 180);
     path.CloseFigure(); // Second figure is closed.

     e.Graphics.DrawPath(new Pen(Color.FromArgb(255, 255, 0, 0), 2), path);

Compilando o código

Os exemplos anteriores foram projetados para uso com o Windows Forms e exigem PaintEventArgs e, que é um parâmetro das Paint evento manipulador.

Consulte também

Referência

GraphicsPath

Outros recursos

Caminhos Construindo e desenho

Usando uma caneta para desenhar linhas e formas