Método Shape.PointToClient

Calcula o local do ponto de tela especificada nas coordenadas do cliente.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (em Microsoft.VisualBasic.PowerPacks.Vs.dll)

Sintaxe

'Declaração
Public Function PointToClient ( _
    position As Point _
) As Point
public Point PointToClient(
    Point position
)
public:
Point PointToClient(
    Point position
)
member PointToClient : 
        position:Point -> Point 
public function PointToClient(
    position : Point
) : Point

Parâmetros

Valor de retorno

Tipo: System.Drawing.Point
A Point que representa o convertido Point, p, nas coordenadas do cliente.

Comentários

O PointToClient método pode ser usado para converter um valor, como um DragEventArgs que retorna as coordenadas de tela no cliente de coordenadas de um formulário.

Exemplos

O exemplo a seguir demonstra como usar o PointToClient método para mover um RectangleShape quando um arquivo de imagem é arrastado para ele.O PointToClient método Move o RectangleShape em relação ao formulário clientes.Por exemplo, se o local de destino for 10 pixels para baixo e 10 pixels à direita do canto superior esquerdo do retângulo, o retângulo será movido para um pixels local 10 para baixo e 10 pixels à direita do canto superior esquerdo do formulário.

Este exemplo requer que você tenha um RectangleShape controle denominado RectangleShape1 em um formulário e que o AllowDrop a propriedade do formulário estiver definida como true.

Private Sub Form1_DragDrop(
    ByVal sender As Object, 
    ByVal e As System.Windows.Forms.DragEventArgs
  ) Handles Me.DragDrop

    ' Determine whether the drop is within the rectangle.
    If RectangleShape1.HitTest(e.X, e.Y) = True Then
        ' Handle file data.
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            ' Assign the file names to a string array, in 
            ' case the user has selected multiple files.
            Dim files As String() = 
              CType(e.Data.GetData(DataFormats.FileDrop), String())
            Try
                ' Assign the first image to the BackGroundImage
                ' property.
                RectangleShape1.BackgroundImage = 
                  Image.FromFile(files(0))
                ' Set the rectangle location relative to the form.
                RectangleShape1.Location = 
                  RectangleShape1.PointToClient(New Point(e.X, e.Y))
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Return
            End Try
        End If
    End If
End Sub
Private Sub Form1_DragEnter(
    ByVal sender As Object, 
    ByVal e As DragEventArgs
  ) Handles MyBase.DragEnter

    ' If the data is a file, display the copy cursor.
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        e.Effect = DragDropEffects.Copy
    Else
        e.Effect = DragDropEffects.None
    End If
End Sub
private void Form1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
    // Determine whether the drop is within the rectangle.
    if (rectangleShape1.HitTest(e.X, e.Y)==true)
        // Handle file data.
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
            // Assign the file names to a string array, in 
            // case the user has selected multiple files.
        {
            string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
            try
            {
                // Assign the first image to the BackGroundImage
                // property.
                rectangleShape1.BackgroundImage = Image.FromFile(files[0]);
                // Set the rectangle location relative to the form.
                rectangleShape1.Location = 
                    rectangleShape1.PointToClient(new Point(e.X, e.Y));
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
    }
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
    // If the data is a file, display the copy cursor.
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        e.Effect = DragDropEffects.Copy;
    }
    else
    {
        e.Effect = DragDropEffects.None;
    }
}

Segurança do .NET Framework

Consulte também

Referência

Shape Classe

Namespace Microsoft.VisualBasic.PowerPacks

Outros recursos

Como: desenhar linhas com o controle de LineShape (Visual Studio)

Como: desenhar formas com os controles de RectangleShape (Visual Studio) e o OvalShape

Introdução à linha e controles Shape (Visual Studio)