Compartir a través de


Shape.PointToClient (Método)

Calcula la ubicación del punto especificado de la pantalla, en coordenadas de cliente.

Espacio de nombres:  Microsoft.VisualBasic.PowerPacks
Ensamblado:  Microsoft.VisualBasic.PowerPacks.Vs (en Microsoft.VisualBasic.PowerPacks.Vs.dll)

Sintaxis

'Declaración
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 devuelto

Tipo: System.Drawing.Point
Point que representa el Point convertido, p, en coordenadas de cliente.

Comentarios

El método de PointToClient se puede utilizar para convertir un valor como DragEventArgs que devuelve las coordenadas de la pantalla en coordenadas del cliente de un formulario.

Ejemplos

El ejemplo siguiente muestra cómo utilizar el método de PointToClient para mover RectangleShape cuando un archivo de imagen se quita en él.El método de PointToClient mueve RectangleShape en relación con el formulario del cliente.Por ejemplo, si la ubicación de destino es 10 píxeles hacia abajo y 10 píxeles a la derecha de la esquina superior izquierda del rectángulo, el rectángulo se bajado a píxeles de una ubicación 10 y 10 píxeles a la derecha de la esquina superior izquierda del formulario.

Este ejemplo requiere tener un control de RectangleShape denominado RectangleShape1 en un formulario y que la propiedad de AllowDrop de formulario está establecida en 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;
    }
}

Seguridad de .NET Framework

Vea también

Referencia

Shape Clase

Microsoft.VisualBasic.PowerPacks (Espacio de nombres)

Otros recursos

Cómo: Dibujar líneas con el control LineShape (Visual Studio)

Cómo: Dibujar formas con los controles OvalShape y RectangleShape (Visual Studio)

Introducción a los controles de líneas y formas (Visual Studio)