Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MousePosition Property
Collapse the table of content
Expand the table of content

Control.MousePosition Property

Gets the position of the mouse cursor in screen coordinates.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

Public Shared ReadOnly Property MousePosition As Point

Property Value

Type: System.Drawing.Point
A Point that contains the coordinates of the mouse cursor relative to the upper-left corner of the screen.

The MousePosition property returns a Point that represents the mouse cursor position at the time the property was referenced. The coordinates indicate the position on the screen, not relative to the control, and are returned regardless of whether the cursor is positioned over the control. The coordinates of the upper-left corner of the screen are 0,0.

The MousePosition property is identical to the Cursor.Position property.

The following code example puts a TreeNode label into an editable state when the user presses ALT+E while the mouse cursor is over the tree node. After the user is done editing the label, the labels cannot be edited again until the ALT+E key combination is pressed again. This example requires that you have a TreeView on a Form. The tree view should also have at least one TreeNode in its Nodes collection.

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 mose cursor, begin editing.  
      Dim editNode As TreeNode = treeView1.GetNodeAt( _
      If (editNode IsNot Nothing) Then
      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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft