.NET Framework Class Library
Cursor.Clip Property

Gets or sets the bounds that represent the clipping rectangle for the cursor.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

Visual Basic (Declaration)
Public Shared Property Clip As Rectangle
Visual Basic (Usage)
Dim value As Rectangle

value = Cursor.Clip

Cursor.Clip = value
C#
public static Rectangle Clip { get; set; }
C++
public:
static property Rectangle Clip {
    Rectangle get ();
    void set (Rectangle value);
}
J#
/** @property */
public static Rectangle get_Clip ()

/** @property */
public static void set_Clip (Rectangle value)
JScript
public static function get Clip () : Rectangle

public static function set Clip (value : Rectangle)

Property Value

The Rectangle that represents the clipping rectangle for the Cursor, in screen coordinates.
Remarks

A clipped cursor is allowed to move only within its clipping rectangle. Generally, the system allows this only if the mouse is currently captured. If the cursor is not currently clipped, the resulting rectangle contains the dimensions of the entire screen.

Example

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()
   ' 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++
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 = 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);
   }
}
J#
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.get_Cursor().Equals(Cursors.get_Default()))) {
        this.set_Cursor(new Cursor(get_Cursor().get_Current().
            get_Handle()));
        Cursor.set_Position(new Point(get_Cursor().get_Position().
            get_X() - 50, get_Cursor().get_Position().get_Y() - 50));
        get_Cursor().set_Clip(new Rectangle(this.get_Location(), 
            this.get_Size()));
    }
} //MoveCursor
.NET Framework Security

Platforms

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

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

Version Information

.NET Framework

Supported in: 2.0, 1.1, 1.0
See Also

Tags :


Page view tracker