Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

Shape.PointToClient-Methode: (Point)

 

Veröffentlicht: Oktober 2016

Rechnet die Position des angegebenen Bildschirmpunkts in Clientkoordinaten um.

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

public Point PointToClient(
	Point position
)

Parameter

p

Der zu konvertierende Bildschirmkoordinaten-Point.

Rückgabewert

Type: System.Drawing.Point

Ein Point, der den konvertierten Point, p, in Clientkoordinaten darstellt.

The PointToClient method can be used to convert a value such as a T:System.Windows.Forms.DragEventArgs that returns screen coordinates into the client coordinates of a form.

The following example demonstrates how to use the PointToClient method to move a T:Microsoft.VisualBasic.PowerPacks.RectangleShape when an image file is dropped onto it. The PointToClient method moves the T:Microsoft.VisualBasic.PowerPacks.RectangleShape relative to the client form. For example, if the drop location is 10 pixels down and 10 pixels to the right of the top-left corner of the rectangle, the rectangle will be moved to a location 10 pixels down and 10 pixels to the right of the top-left corner of the form.

This example requires that you have a T:Microsoft.VisualBasic.PowerPacks.RectangleShape control named RectangleShape1 on a form and that the P:System.Windows.Forms.Control.AllowDrop property of the form is set to true.

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;
    }
}
Zurück zum Anfang
Anzeigen: