This documentation is archived and is not being maintained.

Control::MousePosition Property

Updated: September 2010

Gets the position of the mouse cursor in screen coordinates.

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

static property Point MousePosition {
	Point get ();

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.

   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 mose cursor, begin editing.
         TreeNode^ editNode = treeView1->GetNodeAt( treeView1->PointToClient( Control::MousePosition ) );
         if ( editNode != nullptr )

   void treeView1_AfterLabelEdit( Object^ /*sender*/, NodeLabelEditEventArgs^ /*e*/ )
      // Disable the ability to edit the TreeNode labels.
      treeView1->LabelEdit = false;

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0




September 2010

Added remark about the Cursor::Position property.

Customer feedback.