Shape.PointToClient-Methode
Rechnet die Position des angegebenen Bildschirmpunkts in Clientkoordinaten um.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax
'Declaration
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
Parameter
- position
Typ: System.Drawing.Point
Rückgabewert
Typ: System.Drawing.Point
Ein Point, der den konvertierten Pointp in Clientkoordinaten darstellt.
Hinweise
Die PointToClient-Methode kann verwendet werden, um einen Wert wie DragEventArgs zu konvertieren, der in die Bildschirmkoordinaten Clientkoordinaten eines Formulars zurückgibt.
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die PointToClient-Methode verwendet, um RectangleShape zu bewegen, wenn eine Bilddatei darauf gezogen wird.Die PointToClient-Methode verschiebt RectangleShape relativ zum Client Form.Wenn beispielsweise der Ablagespeicherort 10 Pixel und 10 Pixel nach unten rechts von der linken oberen Ecke des Rechtecks, wird das Rechteck in Pixel einer relativen Satznummer 10 und 10 Pixel nach unten rechts von der linken oberen Ecke des Formulars verschoben.
Dieses Beispiel setzt voraus, dass Sie ein RectangleShape-Steuerelement verfügen, das in einem Formular RectangleShape1 und dass die AllowDrop-Eigenschaft des Formulars auf truefestgelegt ist.
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;
}
}
.NET Framework-Sicherheit
- Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter Verwenden von Bibliotheken aus teilweise vertrauenswürdigem Code.
Siehe auch
Referenz
Microsoft.VisualBasic.PowerPacks-Namespace
Weitere Ressourcen
Gewusst wie: Zeichnen von Linien mit dem LineShape-Steuerelement (Visual Studio)
Einführung in das Line-Steuerelement und das Shape-Steuerelement (Visual Studio)