Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
Cursor Class
 Cursor Constructor (IntPtr)
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
Cursor Constructor (IntPtr)

Initializes a new instance of the Cursor class from the specified Windows handle.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic
Public Sub New ( _
    handle As IntPtr _
)
C#
public Cursor(
    IntPtr handle
)
Visual C++
public:
Cursor(
    IntPtr handle
)
F#
new : 
        handle:IntPtr -> Cursor

Parameters

handle
Type: System..::.IntPtr
An IntPtr that represents the Windows handle of the cursor to create.
ExceptionCondition
ArgumentException

handle is IntPtr..::.Zero.

You must free the cursor handle when you are done with it. For more information about disposing of resources, see Cleaning Up Unmanaged Resources.

The following code 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 requires that you have a Form and a Button to call this code when it is clicked.

Visual Basic
Private Sub MoveCursor()
   ' Set the Current cursor, move the cursor's Position,
   ' and set its clipping rectangle to the form. 

   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 Sub
C#
private void MoveCursor()
{
   // Set the Current cursor, move the cursor's Position,
   // and set its clipping rectangle to the form. 

   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);
}
Visual C++
void MoveCursor()
{
   // Set the Current cursor, move the cursor's Position,
   // and set its clipping rectangle to the form.

   this->Cursor = gcnew 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);

}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker