Ler em inglês

Partilhar via


Point.Explicit(Point to Size) Operador

Definição

Converte a estrutura especificada Point em uma estrutura Size.

C#
public static explicit operator System.Drawing.Size (System.Drawing.Point p);

Parâmetros

p
Point

O Point a ser convertido.

Retornos

O Size que resulta da conversão.

Exemplos

O exemplo de código a seguir cria pontos e tamanhos usando vários dos operadores sobrecarregados definidos para esses tipos. Ele também demonstra como usar a SystemPens classe .

Este exemplo foi projetado para ser usado com Windows Forms. Create um formulário que contém um Button chamado subtractButton. Cole o código no formulário e chame o CreatePointsAndSizes método do método de tratamento de eventos do Paint formulário, passando e como PaintEventArgs.

C#
private void CreatePointsAndSizes(PaintEventArgs e)
{

    // Create the starting point.
    Point startPoint = new Point(subtractButton.Size);

    // Use the addition operator to get the end point.
    Point endPoint = startPoint + new Size(140, 150);

    // Draw a line between the points.
    e.Graphics.DrawLine(SystemPens.Highlight, startPoint, endPoint);

    // Convert the starting point to a size and compare it to the
    // subtractButton size.  
    Size buttonSize = (Size)startPoint;
    if (buttonSize == subtractButton.Size)

        // If the sizes are equal, tell the user.
    {
        e.Graphics.DrawString("The sizes are equal.", 
            new Font(this.Font, FontStyle.Italic), 
            Brushes.Indigo, 10.0F, 65.0F);
    }
}

Aplica-se a

Produto Versões
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1