Export (0) Print
Expand All

Cursors Class

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

System.Object
  System.Windows.Forms.Cursors

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

public sealed class Cursors

The Cursors type exposes the following members.

  NameDescription
Public propertyStatic memberAppStartingGets the cursor that appears when an application starts.
Public propertyStatic memberArrowGets the arrow cursor.
Public propertyStatic memberCrossGets the crosshair cursor.
Public propertyStatic memberDefaultGets the default cursor, which is usually an arrow cursor.
Public propertyStatic memberHandGets the hand cursor, typically used when hovering over a Web link.
Public propertyStatic memberHelpGets the Help cursor, which is a combination of an arrow and a question mark.
Public propertyStatic memberHSplitGets the cursor that appears when the mouse is positioned over a horizontal splitter bar.
Public propertyStatic memberIBeamGets the I-beam cursor, which is used to show where the text cursor appears when the mouse is clicked.
Public propertyStatic memberNoGets the cursor that indicates that a particular region is invalid for the current operation.
Public propertyStatic memberNoMove2DGets 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.
Public propertyStatic memberNoMoveHorizGets the cursor that appears during wheel operations when the mouse is not moving, but the window can be scrolled in a horizontal direction.
Public propertyStatic memberNoMoveVertGets the cursor that appears during wheel operations when the mouse is not moving, but the window can be scrolled in a vertical direction.
Public propertyStatic memberPanEastGets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling horizontally to the right.
Public propertyStatic memberPanNEGets 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.
Public propertyStatic memberPanNorthGets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling vertically in an upward direction.
Public propertyStatic memberPanNWGets 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.
Public propertyStatic memberPanSEGets 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.
Public propertyStatic memberPanSouthGets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling vertically in a downward direction.
Public propertyStatic memberPanSWGets 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.
Public propertyStatic memberPanWestGets the cursor that appears during wheel operations when the mouse is moving and the window is scrolling horizontally to the left.
Public propertyStatic memberSizeAllGets the four-headed sizing cursor, which consists of four joined arrows that point north, south, east, and west.
Public propertyStatic memberSizeNESWGets the two-headed diagonal (northeast/southwest) sizing cursor.
Public propertyStatic memberSizeNSGets the two-headed vertical (north/south) sizing cursor.
Public propertyStatic memberSizeNWSEGets the two-headed diagonal (northwest/southeast) sizing cursor.
Public propertyStatic memberSizeWEGets the two-headed horizontal (west/east) sizing cursor.
Public propertyStatic memberUpArrowGets the up arrow cursor, typically used to identify an insertion point.
Public propertyStatic memberVSplitGets the cursor that appears when the mouse is positioned over a vertical splitter bar.
Public propertyStatic memberWaitCursorGets the wait cursor, typically an hourglass shape.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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;
using System.Drawing;
using System.Windows.Forms;

namespace MCursor
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ComboBox cursorSelectionComboBox;

        private System.Windows.Forms.Panel testPanel;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.ListView cursorEventViewer;
        private System.Windows.Forms.Label label3;

        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        public Form1()
        {
            this.cursorSelectionComboBox = new System.Windows.Forms.ComboBox();
            this.testPanel = new System.Windows.Forms.Panel();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.cursorEventViewer = new System.Windows.Forms.ListView();
            this.label3 = new System.Windows.Forms.Label();

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

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

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

            // Cursor Selection ComboBox 
            this.cursorSelectionComboBox.Location = new System.Drawing.Point(24, 40);
            this.cursorSelectionComboBox.Size = new System.Drawing.Size(152, 21);
            this.cursorSelectionComboBox.TabIndex = 0;
            this.cursorSelectionComboBox.SelectedIndexChanged += 
                 new System.EventHandler(this.cursorSelectionComboBox_SelectedIndexChanged);

            // Cursor Test Panel 
            this.testPanel.BackColor = System.Drawing.SystemColors.ControlDark;
            this.testPanel.Location = new System.Drawing.Point(24, 104);
            this.testPanel.Size = new System.Drawing.Size(152, 160);
            this.testPanel.CursorChanged += new System.EventHandler(this.testPanel_CursorChanged);

            // Cursor Event ListView 
            this.cursorEventViewer.Location = new System.Drawing.Point(184, 40);
            this.cursorEventViewer.Size = new 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 = new System.Drawing.Size(456, 286);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                        this.label3, this.cursorEventViewer,
                                        this.label2, this.label1,
                                        this.testPanel, this.cursorSelectionComboBox});

            this.Text = "Cursors Example";

            // Add all the cursor types to the combobox. 
            foreach (Cursor cursor in CursorList())
            {
                cursorSelectionComboBox.Items.Add(cursor);
            }

        }

        private Cursor [] CursorList()
        {

            // Make an array of all the types of cursors in Windows Forms. 
            return new Cursor [] {
                                     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};

        }

        private void cursorSelectionComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            // Set the cursor in the test panel to be the selected cursor style.
            testPanel.Cursor = (Cursor)cursorSelectionComboBox.SelectedItem;
        }

        private 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().ToString(), "Cursor changed");                

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

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.

private void DrawCursorsOnForm(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 & 
     Cursor.Current == Cursors.Default)
   {
      // Draw the cursor stretched.
      Graphics graphics = this.CreateGraphics();
      Rectangle rectangle = new Rectangle(
        new Point(10,10), new Size(cursor.Size.Width * 2, 
        cursor.Size.Height * 2));
      cursor.DrawStretched(graphics, rectangle);
		
      // Draw the cursor in normal size.
      rectangle.Location = new Point(
      rectangle.Width + rectangle.Location.X, 
        rectangle.Height + rectangle.Location.Y);
      rectangle.Size = cursor.Size;
      cursor.Draw(graphics, rectangle);

      // Dispose of the cursor.
      cursor.Dispose();
   }
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

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