This documentation is archived and is not being maintained.

Cursor.Position Property

Gets or sets the cursor's position.

[Visual Basic]
Public Shared Property Position As Point
[C#]
public static Point Position {get; set;}
[C++]
public: __property static Point get_Position();
public: __property static void set_Position(Point);
[JScript]
public static function get Position() : Point;
public static function set Position(Point);

Property Value

A Point that represents the cursor's position in screen coordinates.

Example

[Visual Basic, C#, C++] The following example creates a cursor from the Current cursor's Handle, changes its position and clipping rectangle. The result is the cursor will move up and to the left 50 pixels from where it is when the code is executed. Additionally, the cursor's clipping rectangle is changed to the bounds of the form (by default it is the user's whole screen). This example assumes you have a Form and a Button to call this code when it is clicked.

[Visual Basic] 
Private Sub MoveCursor()
   ' If the form's cursor is not the Default cursor,
   ' set the Current cursor, move the cursor's Position,
   ' and set its clipping rectangle to the form. 
   If Not Me.Cursor.Equals(Cursors.Default) Then
      Me.Cursor = New Cursor(Cursor.Current.Handle)
      Cursor.Position = New Point(Cursor.Position.X - 50, Cursor.Position.Y - 50)
      Cursor.Clip = New Rectangle(Me.Location, Me.Size)
   End If
End Sub

[C#] 
private void MoveCursor()
{
   // If the form's cursor is not the Default cursor,
   // set the Current cursor, move the cursor's Position,
   // and set its clipping rectangle to the form. 
   if(!this.Cursor.Equals(Cursors.Default))
   {
   this.Cursor = new Cursor(Cursor.Current.Handle);
   Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
   Cursor.Clip = new Rectangle(this.Location, this.Size);
   }
}

[C++] 
private:
   void MoveCursor() {
      // If the form's cursor is not the Default cursor,
      // set the Current cursor, move the cursor's Position,
      // and set its clipping rectangle to the form.
      if (!this->Cursor->Equals(Cursors::Default)) {
         this->Cursor = new System::Windows::Forms::Cursor(Cursor::Current->Handle);
         Cursor::Position =  Point(Cursor::Position.X - 50, Cursor::Position.Y - 50);
         Cursor::Clip =  Rectangle(this->Location, this->Size);
      }
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Cursor Class | Cursor Members | System.Windows.Forms Namespace | Point

Show: