Cursors Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Provides a collection of Cursor objects for use by a Windows Forms application.

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

System::Object
  System.Windows.Forms::Cursors

public ref class Cursors sealed 

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticAppStarting

Gets the cursor that appears when an application starts.

System_CAPS_pubpropertySystem_CAPS_staticArrow

Gets the arrow cursor.

System_CAPS_pubpropertySystem_CAPS_staticCross

Gets the crosshair cursor.

System_CAPS_pubpropertySystem_CAPS_staticDefault

Gets the default cursor, which is usually an arrow cursor.

System_CAPS_pubpropertySystem_CAPS_staticHand

Gets the hand cursor, typically used when hovering over a Web link.

System_CAPS_pubpropertySystem_CAPS_staticHelp

Gets the Help cursor, which is a combination of an arrow and a question mark.

System_CAPS_pubpropertySystem_CAPS_staticHSplit

Gets the cursor that appears when the mouse is positioned over a horizontal splitter bar.

System_CAPS_pubpropertySystem_CAPS_staticIBeam

Gets the I-beam cursor, which is used to show where the text cursor appears when the mouse is clicked.

System_CAPS_pubpropertySystem_CAPS_staticNo

Gets the cursor that indicates that a particular region is invalid for the current operation.

System_CAPS_pubpropertySystem_CAPS_staticNoMove2D

Gets the cursor that appears during wheel operations when the mouse is not moving, but the window can be scrolled in both a horizontal and vertical direction.

System_CAPS_pubpropertySystem_CAPS_staticNoMoveHoriz

Gets the cursor that appears during wheel operations when the mouse is not moving, but the window can be scrolled in a horizontal direction.

System_CAPS_pubpropertySystem_CAPS_staticNoMoveVert

Gets the cursor that appears during wheel operations when the mouse is not moving, but the window can be scrolled in a vertical direction.

System_CAPS_pubpropertySystem_CAPS_staticPanEast

Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling horizontally to the right.

System_CAPS_pubpropertySystem_CAPS_staticPanNE

Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling horizontally and vertically upward and to the right.

System_CAPS_pubpropertySystem_CAPS_staticPanNorth

Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling vertically in an upward direction.

System_CAPS_pubpropertySystem_CAPS_staticPanNW

Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling horizontally and vertically upward and to the left.

System_CAPS_pubpropertySystem_CAPS_staticPanSE

Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling horizontally and vertically downward and to the right.

System_CAPS_pubpropertySystem_CAPS_staticPanSouth

Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling vertically in a downward direction.

System_CAPS_pubpropertySystem_CAPS_staticPanSW

Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling horizontally and vertically downward and to the left.

System_CAPS_pubpropertySystem_CAPS_staticPanWest

Gets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling horizontally to the left.

System_CAPS_pubpropertySystem_CAPS_staticSizeAll

Gets the four-headed sizing cursor, which consists of four joined arrows that point north, south, east, and west.

System_CAPS_pubpropertySystem_CAPS_staticSizeNESW

Gets the two-headed diagonal (northeast/southwest) sizing cursor.

System_CAPS_pubpropertySystem_CAPS_staticSizeNS

Gets the two-headed vertical (north/south) sizing cursor.

System_CAPS_pubpropertySystem_CAPS_staticSizeNWSE

Gets the two-headed diagonal (northwest/southeast) sizing cursor.

System_CAPS_pubpropertySystem_CAPS_staticSizeWE

Gets the two-headed horizontal (west/east) sizing cursor.

System_CAPS_pubpropertySystem_CAPS_staticUpArrow

Gets the up arrow cursor, typically used to identify an insertion point.

System_CAPS_pubpropertySystem_CAPS_staticVSplit

Gets the cursor that appears when the mouse is positioned over a vertical splitter bar.

System_CAPS_pubpropertySystem_CAPS_staticWaitCursor

Gets the wait cursor, typically an hourglass shape.

NameDescription
System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

Some of the Cursor objects in this class can take on a different appearance than those described. The user can change the cursor appearance by adjusting the mouse pointer settings in their operating system. The panning and no move cursors are static and cannot be changed by the operating system.

The panning and no move cursors are used during mouse wheel operations. Depending on the direction the window can be scrolled, the cursor changes to the appropriate no move cursor when the mouse wheel is clicked. The cursor then changes to the appropriate panning cursor as the mouse is moved.

The following example demonstrates changing the mouse cursor using the Control::Cursor property, the Cursor class, and the Cursors class. The example creates a form that contains a ComboBox control, a Panel control, and a ListView control. The ComboBox contains all cursors provided by the Cursors class. When the user selects a mouse cursor in the ComboBox, the Control::Cursor property is set to the selected cursor, which updates the cursor for the Panel. The ListView is updated every time the Control::CursorChanged event occurs.

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

namespace MCursor
{
   public ref class Form1: public System::Windows::Forms::Form
   {
   private:
      System::Windows::Forms::ComboBox^ cursorSelectionComboBox;
      System::Windows::Forms::Panel^ testPanel;
      System::Windows::Forms::Label ^ label1;
      System::Windows::Forms::Label ^ label2;
      System::Windows::Forms::ListView^ cursorEventViewer;
      System::Windows::Forms::Label ^ label3;

   public:
      Form1()
      {
         this->cursorSelectionComboBox = gcnew System::Windows::Forms::ComboBox;
         this->testPanel = gcnew System::Windows::Forms::Panel;
         this->label1 = gcnew System::Windows::Forms::Label;
         this->label2 = gcnew System::Windows::Forms::Label;
         this->cursorEventViewer = gcnew System::Windows::Forms::ListView;
         this->label3 = gcnew System::Windows::Forms::Label;

         // Select Cursor Label
         this->label2->Location = System::Drawing::Point( 24, 16 );
         this->label2->Size = System::Drawing::Size( 80, 16 );
         this->label2->Text = "Select cursor:";

         // Cursor Testing Panel Label
         this->label1->Location = System::Drawing::Point( 24, 80 );
         this->label1->Size = System::Drawing::Size( 144, 23 );
         this->label1->Text = "Cursor testing panel:";

         // Cursor Changed Events Label
         this->label3->Location = System::Drawing::Point( 184, 16 );
         this->label3->Size = System::Drawing::Size( 128, 16 );
         this->label3->Text = "Cursor changed events:";

         // Cursor Selection ComboBox
         this->cursorSelectionComboBox->Location = System::Drawing::Point( 24, 40 );
         this->cursorSelectionComboBox->Size = System::Drawing::Size( 152, 21 );
         this->cursorSelectionComboBox->TabIndex = 0;
         this->cursorSelectionComboBox->SelectedIndexChanged += gcnew System::EventHandler( this, &Form1::cursorSelectionComboBox_SelectedIndexChanged );

         // Cursor Test Panel
         this->testPanel->BackColor = System::Drawing::SystemColors::ControlDark;
         this->testPanel->Location = System::Drawing::Point( 24, 104 );
         this->testPanel->Size = System::Drawing::Size( 152, 160 );
         this->testPanel->CursorChanged += gcnew System::EventHandler( this, &Form1::testPanel_CursorChanged );

         // Cursor Event ListView
         this->cursorEventViewer->Location = System::Drawing::Point( 184, 40 );
         this->cursorEventViewer->Size = System::Drawing::Size( 256, 224 );
         this->cursorEventViewer->TabIndex = 4;
         this->cursorEventViewer->View = System::Windows::Forms::View::List;

         // Set up how the form should be displayed and add the controls to the form.
         this->ClientSize = System::Drawing::Size( 456, 286 );
         array<System::Windows::Forms::Control^>^temp0 = {this->label3,this->cursorEventViewer,this->label2,this->label1,this->testPanel,this->cursorSelectionComboBox};
         this->Controls->AddRange( temp0 );
         this->Text = "Cursors Example";

         // Add all the cursor types to the combobox.
         System::Collections::IEnumerator^ myEnum = CursorList()->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            System::Windows::Forms::Cursor^ cursor = safe_cast<System::Windows::Forms::Cursor^>(myEnum->Current);
            cursorSelectionComboBox->Items->Add( cursor );
         }
      }


   private:
      array<System::Windows::Forms::Cursor^>^ CursorList()
      {

         // Make an array of all the types of cursors in Windows Forms.
         array<System::Windows::Forms::Cursor^>^temp1 = {Cursors::AppStarting,Cursors::Arrow,Cursors::Cross,Cursors::Default,Cursors::Hand,Cursors::Help,Cursors::HSplit,Cursors::IBeam,Cursors::No,Cursors::NoMove2D,Cursors::NoMoveHoriz,Cursors::NoMoveVert,Cursors::PanEast,Cursors::PanNE,Cursors::PanNorth,Cursors::PanNW,Cursors::PanSE,Cursors::PanSouth,Cursors::PanSW,Cursors::PanWest,Cursors::SizeAll,Cursors::SizeNESW,Cursors::SizeNS,Cursors::SizeNWSE,Cursors::SizeWE,Cursors::UpArrow,Cursors::VSplit,Cursors::WaitCursor};
         return temp1;
      }

      void cursorSelectionComboBox_SelectedIndexChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
      {

         // Set the cursor in the test panel to be the selected cursor style.
         testPanel->Cursor = dynamic_cast<System::Windows::Forms::Cursor^>(cursorSelectionComboBox->SelectedItem);
      }

      void testPanel_CursorChanged( Object^ sender, System::EventArgs^ /*e*/ )
      {

         // Build up a String* containing the type of Object* sending the event, and the event.
         String^ cursorEvent = String::Format( "[{0}]: {1}", sender->GetType(), "Cursor changed" );

         // Record this event in the list view.
         this->cursorEventViewer->Items->Add( cursorEvent );
      }

   };

}


[STAThread]
int main()
{
   Application::Run( gcnew MCursor::Form1 );
}

The following example draws the specified cursor on the form in its normal size, and in stretched mode, twice its size. This example assumes that you have a Form and a Cursor object to pass into the method when it is called.

void DrawCursorsOnForm( System::Windows::Forms::Cursor^ cursor )
{

   // If the form's cursor is not the Hand cursor and the
   // Current cursor is the Default, Draw the specified
   // cursor on the form in normal size and twice normal size.
   if ( this->Cursor != Cursors::Hand && System::Windows::Forms::Cursor::Current == Cursors::Default )
   {

      // Draw the cursor stretched.
      Graphics^ graphics = this->CreateGraphics();
      Rectangle rectangle = Rectangle(Point(10,10),System::Drawing::Size( cursor->Size.Width * 2, cursor->Size.Height * 2 ));
      cursor->DrawStretched( graphics, rectangle );

      // Draw the cursor in normal size.
      rectangle.Location = Point(rectangle.Width + rectangle.Location.X,rectangle.Height + rectangle.Location.Y);
      rectangle.Size = cursor->Size;
      cursor->Draw( graphics, rectangle );

      // Dispose of the cursor.
      delete cursor;
   }
}

.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: