Partilhar via


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

  • position
    Tipo: Point

Valor de retorno

Tipo: Point
Um Point que representa o objeto 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 para o cliente as 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 é solto nele. O PointToClient método Move o RectangleShape em relação ao formulário do cliente. Por exemplo, se o local de destino é 10 pixels para baixo e 10 pixels para a direita do canto superior esquerdo do retângulo, o retângulo será movido para um pixels local 10 para baixo e 10 pixels para a 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 do formulário é 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 LineShape (Visual Studio)

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

Introdução aos controles de linha e forma (Visual Studio)