Control.MousePosition Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan posisi kursor mouse dalam koordinat layar.
public:
static property System::Drawing::Point MousePosition { System::Drawing::Point get(); };
public static System.Drawing.Point MousePosition { get; }
static member MousePosition : System.Drawing.Point
Public Shared ReadOnly Property MousePosition As Point
Nilai Properti
yang Point berisi koordinat kursor mouse relatif terhadap sudut kiri atas layar.
Contoh
Contoh kode berikut menempatkan TreeNode label ke dalam status yang dapat diedit ketika pengguna menekan ALT+E saat kursor mouse berada di atas simpul pohon. Setelah pengguna selesai mengedit label, label tidak dapat diedit lagi hingga kombinasi tombol ALT+E ditekan lagi. Contoh ini mengharuskan Anda memiliki TreeView di Form. Tampilan pohon juga harus memiliki setidaknya satu TreeNode dalam koleksinya Nodes .
private:
void treeView1_KeyDown( Object^ /*sender*/, KeyEventArgs^ e )
{
/* If the 'Alt' and 'E' keys are pressed,
* allow the user to edit the TreeNode label. */
if ( e->Alt && e->KeyCode == Keys::E )
{
treeView1->LabelEdit = true;
// If there is a TreeNode under the mouse cursor, begin editing.
TreeNode^ editNode = treeView1->GetNodeAt( treeView1->PointToClient( Control::MousePosition ) );
if ( editNode != nullptr )
{
editNode->BeginEdit();
}
}
}
void treeView1_AfterLabelEdit( Object^ /*sender*/, NodeLabelEditEventArgs^ /*e*/ )
{
// Disable the ability to edit the TreeNode labels.
treeView1->LabelEdit = false;
}
private void treeView1_KeyDown(object sender, KeyEventArgs e)
{
/* If the 'Alt' and 'E' keys are pressed,
* allow the user to edit the TreeNode label. */
if(e.Alt && e.KeyCode == Keys.E)
{
treeView1.LabelEdit = true;
// If there is a TreeNode under the mouse cursor, begin editing.
TreeNode editNode = treeView1.GetNodeAt(
treeView1.PointToClient(System.Windows.Forms.Control.MousePosition));
if(editNode != null)
{
editNode.BeginEdit();
}
}
}
private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
// Disable the ability to edit the TreeNode labels.
treeView1.LabelEdit = false;
}
Private Sub treeView1_KeyDown(sender As Object, _
e As KeyEventArgs) Handles treeView1.KeyDown
' If the 'Alt' and 'E' keys are pressed,
' allow the user to edit the TreeNode label.
If e.Alt And e.KeyCode = Keys.E Then
treeView1.LabelEdit = True
' If there is a TreeNode under the mouse cursor, begin editing.
Dim editNode As TreeNode = treeView1.GetNodeAt( _
treeView1.PointToClient(System.Windows.Forms.Control.MousePosition))
If (editNode IsNot Nothing) Then
editNode.BeginEdit()
End If
End If
End Sub
Private Sub treeView1_AfterLabelEdit(sender As Object, _
e As NodeLabelEditEventArgs) Handles treeView1.AfterLabelEdit
' Disable the ability to edit the TreeNode labels.
treeView1.LabelEdit = False
End Sub
Keterangan
Properti MousePosition mengembalikan Point yang mewakili posisi kursor mouse pada saat properti dirujuk. Koordinat menunjukkan posisi pada layar, tidak relatif terhadap kontrol, dan dikembalikan terlepas dari apakah kursor diposisikan di atas kontrol. Koordinat sudut kiri atas layar adalah 0,0.
Properti MousePosition ini identik dengan Cursor.Position properti .