This documentation is archived and is not being maintained.

Cursor Constructor

.NET Framework 1.1

Initializes a new instance of the Cursor class.

Overload List

Initializes a new instance of the Cursor class from the specified Windows handle.

[Visual Basic] Public Sub New(IntPtr)
[C#] public Cursor(IntPtr);
[C++] public: Cursor(IntPtr);
[JScript] public function Cursor(IntPtr);

Initializes a new instance of the Cursor class from the specified data stream.

[Visual Basic] Public Sub New(Stream)
[C#] public Cursor(Stream);
[C++] public: Cursor(Stream*);
[JScript] public function Cursor(Stream);

Initializes a new instance of the Cursor class from the specified file.

[Visual Basic] Public Sub New(String)
[C#] public Cursor(string);
[C++] public: Cursor(String*);
[JScript] public function Cursor(String);

Initializes a new instance of the Cursor class from the specified resource with the specified resource type.

[Visual Basic] Public Sub New(Type, String)
[C#] public Cursor(Type, string);
[C++] public: Cursor(Type*, String*);
[JScript] public function Cursor(Type, String);

Example

[Visual Basic, C#, C++] The following example displays a form that demonstrates using a custom cursor by using the System.Windows.Forms.Cursor.#ctor constructor. The custom Cursor is embedded in the applications resource file. The example assumes that you have a cursor contained in a cursor file named MyCursor.cur. To compile this example using the command line, include the following flag: /res:MyCursor.Cur, CustomCursor.MyCursor.Cur

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the Cursor constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Namespace CustomCursor
   
   Public Class Form1
      Inherits System.Windows.Forms.Form
      
      <System.STAThread()> _
      Public Shared Sub Main()
         System.Windows.Forms.Application.Run(New Form1())
      End Sub 'Main

      Public Sub New()

         Me.ClientSize = New System.Drawing.Size(292, 266)
         Me.Text = "Cursor Example"
         
         ' Looks namespace.MyCursor.cur in the assemblies manifest.
         
         ' The following generates a cursor from an embedded resource.
         ' To add a custom cursor, create or use an existing 16x16 bitmap
         '        1. Add a new cursor file to your project: 
         '                File->Add New Item->Local Project Items->Cursor File
         '        2. Select 16x16 image type:
         '                Image->Current Icon Image Types->16x16
         ' --- To make the custom cursor an embedded resource  ---
         ' In Visual Studio:
         '        1. Select the cursor file in the Solution Explorer
         '        2. Choose View->Properties.
         '        3. In the properties window switch "Build Action" to "Embedded"
         ' On the command line:
         '        Add the following flag:
         '            /res:CursorFileName.Cur,Namespace.CursorFileName.Cur
         '
         ' The following line uses the namespace from the passed-in type
         ' and looks for CustomCursor.MyCursor.Cur in the assemblies manifest.
     ' NOTE: The cursor name is acase sensitive.        
     
         Me.Cursor = New Cursor(Me.GetType(), "MyCursor.Cur") 
      End Sub 'New       
   End Class 'Form1
End Namespace 'CustomCursor

[C#] 
using System;
using System.Drawing;
using System.Windows.Forms;

namespace CustomCursor
{
    public class Form1 : System.Windows.Forms.Form
    {
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        public Form1()
        {
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Text = "Cursor Example";
            
            // The following generates a cursor from an embedded resource.
            
            // To add a custom cursor, create or use an existing 16x16 bitmap
            //        1. Add a new cursor file to your project: 
            //                File->Add New Item->Local Project Items->Cursor File
            //        2. Select 16x16 image type:
            //                Image->Current Icon Image Types->16x16

            // --- To make the custom cursor an embedded resource  ---
            
            // In Visual Studio:
            //        1. Select the cursor file in the Solution Explorer
            //        2. Choose View->Properties.
            //        3. In the properties window switch "Build Action" to "Embedded"

            // On the command line:
            //        Add the following flag:
            //            /res:CursorFileName.Cur,Namespace.CursorFileName.Cur
            //        
            //        Where "Namespace" is the namespace in which you want to use the cursor
            //        and   "CursorFileName.Cur" is the cursor filename.

            // The following line uses the namespace from the passed-in type
            // and looks for CustomCursor.MyCursor.Cur in the assemblies manifest.
        // NOTE: The cursor name is acase sensitive.
            this.Cursor = new Cursor(GetType(), "MyCursor.Cur");  
           
        }
    }
}

[C++] 

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

namespace CustomCursor {
public __gc class Form1 : public System::Windows::Forms::Form {

public:
    Form1() {
        this->ClientSize = System::Drawing::Size(292, 266);
        this->Text = S"Cursor Example";

        // The following generates a cursor from an embedded resource.

        // To add a custom cursor, create or use an existing 16x16 bitmap
        //        1. Add a new cursor file to your project:
        //                File->Add New Item->Local Project Items->Cursor File
        //        2. Select 16x16 image type:
        //                Image->Current Icon Image Types->16x16

        // --- To make the custom cursor an embedded resource  ---

        // In Visual Studio:
        //        1. Select the cursor file in the Solution Explorer
        //        2. Choose View->Properties.
        //        3. In the properties window switch "Build Action" to "Embedded"

        // On the command line:
        //        Add the following flag:
        //            /res:CursorFileName.Cur, Namespace.CursorFileName.Cur
        //
        //        Where "Namespace" is the namespace in which you want to use the cursor
        //        and   "CursorFileName.Cur" is the cursor filename.

        // The following line uses the namespace from the passed-in type
        // and looks for CustomCursor.MyCursor.Cur in the assemblies manifest.
        // NOTE: The cursor name is case sensitive.
        this->Cursor = new System::Windows::Forms::Cursor(GetType(), S"MyCursor.Cur");

    }
};
}
[STAThread]
int main() {
    Application::Run(new CustomCursor::Form1());
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Cursor Class | Cursor Members | System.Windows.Forms Namespace

Show: