This documentation is archived and is not being maintained.

Cursor.Handle Property

Gets the handle of the cursor.

[Visual Basic]
Public ReadOnly Property Handle As IntPtr
[C#]
public IntPtr Handle {get;}
[C++]
public: __property IntPtr get_Handle();
[JScript]
public function get Handle() : IntPtr;

Property Value

An IntPtr that represents the cursor's handle.

Exceptions

Exception Type Condition
Exception The handle value is IntPtr.Zero.

Remarks

This is not a copy of the handle; do not dispose of it.

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 | Dispose

Show: