Cursors Class

Defines a set of default cursors.

System.Object
  System.Windows.Input.Cursors

Namespace:  System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

'Declaration
Public NotInheritable Class Cursors

The Cursors type exposes the following members.

  NameDescription
Public propertyStatic memberAppStartingGets the Cursor that appears when an application is starting.
Public propertyStatic memberArrowGets the Arrow Cursor.
Public propertyStatic memberArrowCDGets the arrow with a compact disk Cursor.
Public propertyStatic memberCrossGets the crosshair Cursor.
Public propertyStatic memberHandGets a hand Cursor.
Public propertyStatic memberHelpGets a help Cursor which is a combination of an arrow and a question mark.
Public propertyStatic memberIBeamGets an I-beam Cursor, which is used to show where the text cursor appears when the mouse is clicked.
Public propertyStatic memberNoGets a Cursor with which indicates that a particular region is invalid for a given operation.
Public propertyStatic memberNoneGets a special cursor that is invisible.
Public propertyStatic memberPenGets a pen Cursor.
Public propertyStatic memberScrollAllGets the scroll all Cursor.
Public propertyStatic memberScrollEGets the scroll east Cursor.
Public propertyStatic memberScrollNGets the scroll north Cursor.
Public propertyStatic memberScrollNEGets the scroll northeast cursor.
Public propertyStatic memberScrollNSGets the scroll north/south cursor.
Public propertyStatic memberScrollNWGets a scroll northwest cursor.
Public propertyStatic memberScrollSGets the scroll south Cursor.
Public propertyStatic memberScrollSEGets a south/east scrolling Cursor.
Public propertyStatic memberScrollSWGets the scroll southwest Cursor.
Public propertyStatic memberScrollWGets the scroll west Cursor.
Public propertyStatic memberScrollWEGets a west/east scrolling Cursor.
Public propertyStatic memberSizeAllGets a four-headed sizing Cursor, which consists of four joined arrows that point north, south, east, and west.
Public propertyStatic memberSizeNESWGets a two-headed northeast/southwest sizing Cursor.
Public propertyStatic memberSizeNSGets a two-headed north/south sizing Cursor.
Public propertyStatic memberSizeNWSEGets a two-headed northwest/southeast sizing Cursor.
Public propertyStatic memberSizeWEGets a two-headed west/east sizing Cursor.
Public propertyStatic memberUpArrowGets an up arrow Cursor, which is typically used to identify an insertion point.
Public propertyStatic memberWaitSpecifies a wait (or hourglass) Cursor.
Top

This static class defines a set of default cursors common to applications.

The various static properties defining cursors are not directly usable in XAML, but are indirectly used through two possible mechanisms:

  • The Cursor class performs type conversion on any XAML attribute that takes type Cursor, such that a value of the CursorType enumeration specified as the attribute value will evaluate to one of the static Cursors properties.

  • A static property value can be used through the x:Static Markup Extension.

This example shows how to change the Cursor of the mouse pointer for a specific element and for the application.

This example consists of a Extensible Application Markup Language (XAML) file and a code behind file.

The user interface is created, which consists of a ComboBox to select the desired Cursor, a pair of RadioButton objects to determine if the cursor change applies to only a single element or applies to the entire application, and a Border which is the element that the new cursor is applied to.

<StackPanel>
  <Border Width="300">
    <StackPanel Orientation="Horizontal"
                HorizontalAlignment="Center">
      <StackPanel Margin="10">
        <Label HorizontalAlignment="Left">Cursor Type</Label>
        <ComboBox Width="100"
                  SelectionChanged="CursorTypeChanged"
                  HorizontalAlignment="Left"
                  Name="CursorSelector">
          <ComboBoxItem Content="AppStarting" />
          <ComboBoxItem Content="ArrowCD" />
          <ComboBoxItem Content="Arrow" />
          <ComboBoxItem Content="Cross" />
          <ComboBoxItem Content="HandCursor" />
          <ComboBoxItem Content="Help" />
          <ComboBoxItem Content="IBeam" />
          <ComboBoxItem Content="No" />
          <ComboBoxItem Content="None" />
          <ComboBoxItem Content="Pen" />
          <ComboBoxItem Content="ScrollSE" />
          <ComboBoxItem Content="ScrollWE" />
          <ComboBoxItem Content="SizeAll" />
          <ComboBoxItem Content="SizeNESW" />
          <ComboBoxItem Content="SizeNS" />
          <ComboBoxItem Content="SizeNWSE" />
          <ComboBoxItem Content="SizeWE" />
          <ComboBoxItem Content="UpArrow" />
          <ComboBoxItem Content="WaitCursor" />
          <ComboBoxItem Content="Custom" />
        </ComboBox>
      </StackPanel>
      <!-- The user can select different cursor types using this ComboBox -->
      <StackPanel Margin="10">
        <Label HorizontalAlignment="Left">Scope of Cursor</Label>
        <StackPanel>
          <RadioButton Name="rbScopeElement" IsChecked="True"
                       Checked="CursorScopeSelected">Display Area Only</RadioButton>
          <RadioButton Name="rbScopeApplication"
                       Checked="CursorScopeSelected">Entire Appliation</RadioButton>
        </StackPanel>
      </StackPanel>
    </StackPanel>
  </Border>
  <!-- When the mouse pointer is over this Border -->
  <!-- the selected cursor type is shown -->
  <Border Name="DisplayArea" Height="250" Width="400"
          Margin="20" Background="AliceBlue">
    <Label HorizontalAlignment="Center">
      Move Mouse Pointer Over This Area
    </Label>
  </Border>
</StackPanel>

The following code behind creates a SelectionChanged event handler which is called when the cursor type is changed in the ComboBox. A switch statement filters on the cursor name and sets the Cursor property on the Border which is named DisplayArea.

If the cursor change is set to "Entire Application", the OverrideCursor property is set to the Cursor property of the Border control. This forces the cursor to change for the whole application.

' When the Radiobox changes, a new cursor type is set 
Private Sub CursorTypeChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)

    Dim item As String = CType(e.Source, ComboBox).SelectedItem.Content.ToString()

    Select Case item
        Case "AppStarting"
            DisplayArea.Cursor = Cursors.AppStarting
        Case "ArrowCD"
            DisplayArea.Cursor = Cursors.ArrowCD
        Case "Arrow"
            DisplayArea.Cursor = Cursors.Arrow
        Case "Cross"
            DisplayArea.Cursor = Cursors.Cross
        Case "HandCursor"
            DisplayArea.Cursor = Cursors.Hand
        Case "Help"
            DisplayArea.Cursor = Cursors.Help
        Case "IBeam"
            DisplayArea.Cursor = Cursors.IBeam
        Case "No"
            DisplayArea.Cursor = Cursors.No
        Case "None"
            DisplayArea.Cursor = Cursors.None
        Case "Pen"
            DisplayArea.Cursor = Cursors.Pen
        Case "ScrollSE"
            DisplayArea.Cursor = Cursors.ScrollSE
        Case "ScrollWE"
            DisplayArea.Cursor = Cursors.ScrollWE
        Case "SizeAll"
            DisplayArea.Cursor = Cursors.SizeAll
        Case "SizeNESW"
            DisplayArea.Cursor = Cursors.SizeNESW
        Case "SizeNS"
            DisplayArea.Cursor = Cursors.SizeNS
        Case "SizeNWSE"
            DisplayArea.Cursor = Cursors.SizeNWSE
        Case "SizeWE"
            DisplayArea.Cursor = Cursors.SizeWE
        Case "UpArrow"
            DisplayArea.Cursor = Cursors.UpArrow
        Case "WaitCursor"
            DisplayArea.Cursor = Cursors.Wait
        Case "Custom"
            DisplayArea.Cursor = CustomCursor
    End Select 

    ' if the cursor scope is set to the entire application 
    ' use OverrideCursor to force the cursor for all elements 
    If (cursorScopeElementOnly = False) Then
        Mouse.OverrideCursor = DisplayArea.Cursor
    End If 


End Sub

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft