Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Control.CursorChanged Event

Occurs when the value of the Cursor property changes.

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

event EventHandler^ CursorChanged {
	void add (EventHandler^ value);
	void remove (EventHandler^ value);
/** @event */
public void add_CursorChanged (EventHandler value)

/** @event */
public void remove_CursorChanged (EventHandler value)

JScript supports the use of events, but not the declaration of new ones.

This event is raised if the Cursor property is changed by either a programmatic modification or user interaction.

For more information about handling events, see Consuming Events.

The following code 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
      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;

         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 );

      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 );



int main()
   Application::Run( gcnew MCursor::Form1 );

package MCursor;

import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;
import System.Collections.*;

public class Form1 extends 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;

    /** @attribute STAThread()
    public static void main(String[] args)
        Application.Run(new Form1());
    } //main

    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.set_Location(new System.Drawing.Point(24, 16));
        this.label2.set_Size(new System.Drawing.Size(80, 16));
        this.label2.set_Text("Select cursor:");
        // Cursor Testing Panel Label
        this.label1.set_Location(new System.Drawing.Point(24, 80));
        this.label1.set_Size(new System.Drawing.Size(144, 23));
        this.label1.set_Text("Cursor testing panel:");
        // Cursor Changed Events Label
        this.label3.set_Location(new System.Drawing.Point(184, 16));
        this.label3.set_Size(new System.Drawing.Size(128, 16));
        this.label3.set_Text("Cursor changed events:");
        // Cursor Selection ComboBox
            new System.Drawing.Point(24, 40));
            new System.Drawing.Size(152, 21));
            new System.EventHandler(
        // Cursor Test Panel
        this.testPanel.set_Location(new System.Drawing.Point(24, 104));
        this.testPanel.set_Size(new System.Drawing.Size(152, 160));
        this.testPanel.add_CursorChanged(new System.EventHandler(
        // Cursor Event ListView
        this.cursorEventViewer.set_Location(new System.Drawing.Point(184, 40));
        this.cursorEventViewer.set_Size(new System.Drawing.Size(256, 224));
        // Set up how the form should be displayed and add the controls to the 
        // form.
        this.set_ClientSize(new System.Drawing.Size(456, 286));
        this.get_Controls().AddRange(new System.Windows.Forms.Control[] { 
            this.label3, this.cursorEventViewer, this.label2, this.label1,
            this.testPanel, this.cursorSelectionComboBox });

        this.set_Text("Cursors Example");

        IEnumerator myEnum = CursorList().GetEnumerator();
        // Add all the cursor types to the combobox.
        while (myEnum.MoveNext()) {
            Cursor cursor = ( Cursor)myEnum.get_Current();
    } //Form1

    private Cursor[] CursorList()
        // Make an array of all the types of cursors in Windows Forms.
        return new Cursor[] { Cursors.get_AppStarting(), Cursors.get_Arrow(), 
            Cursors.get_Cross(), Cursors.get_Default(), Cursors.get_Hand(), 
            Cursors.get_Help(), Cursors.get_HSplit(), Cursors.get_IBeam(), 
            Cursors.get_No(), Cursors.get_NoMove2D(), Cursors.get_NoMoveHoriz(), 
            Cursors.get_NoMoveVert(), Cursors.get_PanEast(), 
            Cursors.get_PanNE(), Cursors.get_PanNorth(), Cursors.get_PanNW(),
            Cursors.get_PanSE(), Cursors.get_PanSouth(), Cursors.get_PanSW(),
            Cursors.get_PanWest(), Cursors.get_SizeAll(), 
            Cursors.get_SizeNESW(), Cursors.get_SizeNS(), 
            Cursors.get_SizeNWSE(), Cursors.get_SizeWE(), 
            Cursors.get_UpArrow(), Cursors.get_VSplit(), 
            Cursors.get_WaitCursor() };
    } //CursorList

    private void cursorSelectionComboBox_SelectedIndexChanged(Object sender,
        System.EventArgs e)
        // Set the cursor in the test panel to be the selected cursor style.
    } //cursorSelectionComboBox_SelectedIndexChanged

    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.
    } //testPanel_CursorChanged
} //Form1

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.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

© 2015 Microsoft