Cursor 클래스

정의

마우스 포인터를 그리는 데 사용되는 이미지를 나타냅니다.

public ref class Cursor sealed : IDisposable, System::Runtime::Serialization::ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.CursorConverter))]
[System.Serializable]
public sealed class Cursor : IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.CursorConverter))]
public sealed class Cursor : IDisposable, System.Runtime.Serialization.ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.CursorConverter))>]
[<System.Serializable>]
type Cursor = class
    interface IDisposable
    interface ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.CursorConverter))>]
type Cursor = class
    interface IDisposable
    interface ISerializable
Public NotInheritable Class Cursor
Implements IDisposable, ISerializable
상속
Cursor
특성
구현

예제

다음 코드 예제에서는 사용자 지정 커서를 사용하는 방법을 보여 주는 폼을 표시합니다. 사용자 지정 Cursor 애플리케이션의 리소스 파일에 포함 됩니다. 이 예제에서는 커서 MyCursor.cur파일에 포함된 커서가 필요합니다. 명령줄을 사용하여 이 예제를 컴파일하려면 다음 플래그를 포함합니다. /res:MyCursor.Cur, CustomCursor.MyCursor.Cur

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 a bitmap
            //        1. Add a new cursor file to your project: 
            //                Project->Add New Item->General->Cursor File

            // --- 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 Resources"

            // 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");  
        }
    }
}
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

      Public Sub New()

         Me.ClientSize = New System.Drawing.Size(292, 266)
         Me.Text = "Cursor Example"
         
        ' The following generates a cursor from an embedded resource.
         
        'To add a custom cursor, create a bitmap
        '       1. Add a new cursor file to your project: 
        '               Project->Add New Item->General->Cursor File

        '--- 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 Resources"

        '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.
        Me.Cursor = New Cursor(Me.GetType(), "MyCursor.cur")
      End Sub
   End Class
End Namespace 'CustomCursor

다음 코드 예제에서는 컨트롤에 고객 정보를 표시합니다 TreeView . 루트 트리 노드는 고객 이름을 표시하고 자식 트리 노드는 각 고객에게 할당된 주문 번호를 표시합니다. 이 예제에서는 1,000명의 고객이 각각 15개의 주문으로 표시됩니다. 개체를 만들고 그리는 동안 TreeView 에는 메서드 및 Cursor EndUpdate 메서드를 사용하여 BeginUpdate 다시 그리 TreeView 기를 표시하지 TreeNode 않습니다. 이 예제에서는 명명 된 커서 파일이 있어야 MyWait.cur 애플리케이션 디렉터리에서입니다. 또한 개체 컬렉션을 보유할 수 있고 컨트롤FormOrder TreeView 인스턴스를 만든 개체가 필요합니다Customer.

// The basic Customer class.
ref class Customer: public System::Object
{
private:
   String^ custName;

protected:
   ArrayList^ custOrders;

public:
   Customer( String^ customername )
   {
      custName = "";
      custOrders = gcnew ArrayList;
      this->custName = customername;
   }


   property String^ CustomerName 
   {
      String^ get()
      {
         return this->custName;
      }

      void set( String^ value )
      {
         this->custName = value;
      }

   }

   property ArrayList^ CustomerOrders 
   {
      ArrayList^ get()
      {
         return this->custOrders;
      }

   }

};


// End Customer class
// The basic customer Order class.
ref class Order: public System::Object
{
private:
   String^ ordID;

public:
   Order( String^ orderid )
   {
      ordID = "";
      this->ordID = orderid;
   }


   property String^ OrderID 
   {
      String^ get()
      {
         return this->ordID;
      }

      void set( String^ value )
      {
         this->ordID = value;
      }

   }

};
// End Order class



void FillMyTreeView()
{
   // Add customers to the ArrayList of Customer objects.
   for ( int x = 0; x < 1000; x++ )
   {
      customerArray->Add( gcnew Customer( "Customer " + x ) );
   }
   
   // Add orders to each Customer object in the ArrayList.
   IEnumerator^ myEnum = customerArray->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Customer^ customer1 = safe_cast<Customer^>(myEnum->Current);
      for ( int y = 0; y < 15; y++ )
      {
         customer1->CustomerOrders->Add( gcnew Order( "Order " + y ) );
      }
   }

   // Display a wait cursor while the TreeNodes are being created.
   ::Cursor::Current = gcnew System::Windows::Forms::Cursor( "MyWait.cur" );
   
   // Suppress repainting the TreeView until all the objects have been created.
   treeView1->BeginUpdate();
   
   // Clear the TreeView each time the method is called.
   treeView1->Nodes->Clear();
   
   // Add a root TreeNode for each Customer object in the ArrayList.
   myEnum = customerArray->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Customer^ customer2 = safe_cast<Customer^>(myEnum->Current);
      treeView1->Nodes->Add( gcnew TreeNode( customer2->CustomerName ) );
      
      // Add a child treenode for each Order object in the current Customer object.
      IEnumerator^ myEnum = customer2->CustomerOrders->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Order^ order1 = safe_cast<Order^>(myEnum->Current);
         treeView1->Nodes[ customerArray->IndexOf( customer2 ) ]->Nodes->Add( gcnew TreeNode( customer2->CustomerName + "." + order1->OrderID ) );
      }
   }
   
   // Reset the cursor to the default for all controls.
   ::Cursor::Current = Cursors::Default;
   
   // Begin repainting the TreeView.
   treeView1->EndUpdate();
}

// The basic Customer class.
public class Customer : System.Object
{
   private string custName = "";
   protected ArrayList custOrders = new ArrayList();

   public Customer(string customername)
   {
      this.custName = customername;
   }

   public string CustomerName
   {      
      get{return this.custName;}
      set{this.custName = value;}
   }

   public ArrayList CustomerOrders 
   {
      get{return this.custOrders;}
   }
} // End Customer class 

// The basic customer Order class.
public class Order : System.Object
{
   private string ordID = "";

   public Order(string orderid)
   {
      this.ordID = orderid;
   }

   public string OrderID
   {      
      get{return this.ordID;}
      set{this.ordID = value;}
   }
} // End Order class

// Create a new ArrayList to hold the Customer objects.
private ArrayList customerArray = new ArrayList(); 

private void FillMyTreeView()
{
   // Add customers to the ArrayList of Customer objects.
   for(int x=0; x<1000; x++)
   {
      customerArray.Add(new Customer("Customer" + x.ToString()));
   }

   // Add orders to each Customer object in the ArrayList.
   foreach(Customer customer1 in customerArray)
   {
      for(int y=0; y<15; y++)
      {
         customer1.CustomerOrders.Add(new Order("Order" + y.ToString()));    
      }
   }

   // Display a wait cursor while the TreeNodes are being created.
   Cursor.Current = new Cursor("MyWait.cur");
        
   // Suppress repainting the TreeView until all the objects have been created.
   treeView1.BeginUpdate();

   // Clear the TreeView each time the method is called.
   treeView1.Nodes.Clear();

   // Add a root TreeNode for each Customer object in the ArrayList.
   foreach(Customer customer2 in customerArray)
   {
      treeView1.Nodes.Add(new TreeNode(customer2.CustomerName));
          
      // Add a child treenode for each Order object in the current Customer object.
      foreach(Order order1 in customer2.CustomerOrders)
      {
         treeView1.Nodes[customerArray.IndexOf(customer2)].Nodes.Add(
           new TreeNode(customer2.CustomerName + "." + order1.OrderID));
      }
   }

   // Reset the cursor to the default for all controls.
   Cursor.Current = Cursors.Default;

   // Begin repainting the TreeView.
   treeView1.EndUpdate();
}
Public Class Customer
   Inherits [Object]
   Private custName As String = ""
   Friend custOrders As New ArrayList()

   Public Sub New(ByVal customername As String)
      Me.custName = customername
   End Sub

   Public Property CustomerName() As String
      Get
         Return Me.custName
      End Get
      Set(ByVal Value As String)
         Me.custName = Value
      End Set
   End Property

   Public ReadOnly Property CustomerOrders() As ArrayList
      Get
         Return Me.custOrders
      End Get
   End Property
End Class


Public Class Order
   Inherits [Object]
   Private ordID As String

   Public Sub New(ByVal orderid As String)
      Me.ordID = orderid
   End Sub

   Public Property OrderID() As String
      Get
         Return Me.ordID
      End Get
      Set(ByVal Value As String)
         Me.ordID = Value
      End Set
   End Property
End Class

' Create a new ArrayList to hold the Customer objects.
Private customerArray As New ArrayList()

Private Sub FillMyTreeView()
   ' Add customers to the ArrayList of Customer objects.
   Dim x As Integer
   For x = 0 To 999
      customerArray.Add(New Customer("Customer" + x.ToString()))
   Next x

   ' Add orders to each Customer object in the ArrayList.
   Dim customer1 As Customer
   For Each customer1 In customerArray
      Dim y As Integer
      For y = 0 To 14
         customer1.CustomerOrders.Add(New Order("Order" + y.ToString()))
      Next y
   Next customer1

   ' Display a wait cursor while the TreeNodes are being created.
   Cursor.Current = New Cursor("MyWait.cur")

   ' Suppress repainting the TreeView until all the objects have been created.
   treeView1.BeginUpdate()

   ' Clear the TreeView each time the method is called.
   treeView1.Nodes.Clear()

   ' Add a root TreeNode for each Customer object in the ArrayList.
   Dim customer2 As Customer
   For Each customer2 In customerArray
      treeView1.Nodes.Add(New TreeNode(customer2.CustomerName))

      ' Add a child TreeNode for each Order object in the current Customer object.
      Dim order1 As Order
      For Each order1 In customer2.CustomerOrders
         treeView1.Nodes(customerArray.IndexOf(customer2)).Nodes.Add( _
    New TreeNode(customer2.CustomerName + "." + order1.OrderID))
      Next order1
   Next customer2

   ' Reset the cursor to the default for all controls.
   Cursor.Current = System.Windows.Forms.Cursors.Default

   ' Begin repainting the TreeView.
   treeView1.EndUpdate()
End Sub

설명

커서가 작은 사진을 화면의 위치가 트랙볼, 펜, 마우스 등의 포인팅 디바이스에 의해 제어 됩니다. 포인팅 디바이스를 이동 하면 운영 체제에 따라 커서를 이동 합니다.

여러 커서 셰이프를 사용하여 마우스가 어떤 작업을 수행할지 사용자에게 알릴 수 있습니다. 예를 들어 텍스트를 Cursors.IBeam 편집하거나 선택할 때 커서가 일반적으로 표시됩니다. 대기 커서는 일반적으로 프로세스가 현재 실행 중임을 사용자에게 알리는 데 사용됩니다. 사용자가 대기하게 될 수 있는 프로세스의 예로는 파일을 열거나, 파일을 저장하거나, 컨트롤(예: DataGridListBox )을 채우거나 TreeView 많은 양의 데이터를 입력하는 것이 있습니다.

클래스에서 파생되는 모든 컨트롤에는 Control 속성이 있습니다 Cursor . 마우스 포인터가 컨트롤의 범위 내에 있을 때 표시되는 커서를 변경하려면 컨트롤의 속성에 Cursor 할당 Cursor 합니다. 할당 하 여 애플리케이션 수준에서 커서를 표시할 수는 또는 CursorCurrent 속성입니다. 예를 들어, 애플리케이션의 용도 텍스트 파일을 편집 하려면 설정할 수 있습니다 합니다 Current 속성을 Cursors.WaitCursor 파일을 로드 하거나 처리 중인 모든 마우스 이벤트를 방지 하기 위해 저장 하는 동안 애플리케이션 위에 대기 커서를 표시 합니다. 프로세스가 완료 되 면 설정 된 Current 속성을 Cursors.Default 각 컨트롤 형식에 대해 적절 한 커서를 표시 하려면 애플리케이션에 대 한 합니다.

참고

호출 하는 경우 Application.DoEvents 다시 설정 하기 전에 Current 속성을 다시 합니다 Cursors.Default 커서 애플리케이션 마우스 이벤트를 수신 대기 하는 다시 시작 됩니다 하 고 적절 한 표시 하는 다시 시작 됩니다 Cursor 애플리케이션에서 각 컨트롤에 대 한 합니다.

커서 개체는 기존 Cursor, 표준 Cursor 파일, 리소스 또는 데이터 스트림의 핸들과 같은 여러 원본에서 만들 수 있습니다.

참고

이 클래스는 Cursor 애니메이션 커서(.ani 파일) 또는 흑백 이외의 색이 있는 커서를 지원하지 않습니다.

커서로 사용하는 이미지가 너무 작으면 메서드를 사용하여 DrawStretched 이미지가 커서의 범위를 채우도록 할 수 있습니다. 메서드를 호출하여 커서를 일시적으로 숨기고 메서드를 Hide 호출 Show 하여 복원할 수 있습니다.

.NET Framework 4.5.2 Cursor 부터 app.config 파일에 다음 항목이 포함된 경우 시스템 DPI 설정에 따라 크기가 조정됩니다.

<appSettings>  
  <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />  
</appSettings>  

생성자

Cursor(IntPtr)

지정된 창 핸들에서 Cursor 클래스의 새 인스턴스를 초기화합니다.

Cursor(Stream)

지정된 데이터 스트림에서 Cursor 클래스의 새 인스턴스를 초기화합니다.

Cursor(String)

지정된 파일에서 Cursor 클래스의 새 인스턴스를 초기화합니다.

Cursor(Type, String)

지정된 리소스 유형을 사용하여 지정된 리소스에서 Cursor 클래스의 새 인스턴스를 초기화합니다.

속성

Clip

커서의 클리핑 사각형을 나타내는 범위를 가져오거나 설정합니다.

Current

마우스 커서를 나타내는 커서 개체를 가져오거나 설정합니다.

Handle

커서의 핸들을 가져옵니다.

HotSpot

커서 핫 스폿을 가져옵니다.

Position

커서의 위치를 가져오거나 설정합니다.

Size

커서 개체의 크기를 가져옵니다.

Tag

Cursor에 대한 데이터가 들어 있는 개체를 가져오거나 설정합니다.

메서드

CopyHandle()

Cursor의 핸들을 복사합니다.

Dispose()

Cursor에서 사용하는 모든 리소스를 해제합니다.

Draw(Graphics, Rectangle)

지정된 범위 내의 지정된 표면에 커서를 그립니다.

DrawStretched(Graphics, Rectangle)

지정된 범위 내의 지정된 표면에 늘이기 형식으로 커서를 그립니다.

Equals(Object)

커서가 지정된 Cursor와 같은지 여부를 나타내는 값을 반환합니다.

Finalize()

가비지 컬렉션이 회수하기 전에 개체가 리소스를 해제하고 다른 정리 작업을 수행할 수 있게 합니다.

GetHashCode()

현재 Cursor에 대한 해시 코드를 검색합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
Hide()

커서를 숨깁니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Show()

커서를 표시합니다.

ToString()

Cursor를 나타내는 사람이 인식할 수 있는 문자열을 검색합니다.

연산자

Equality(Cursor, Cursor)

Cursor 클래스의 두 인스턴스가 같은지 여부를 나타내는 값을 반환합니다.

Inequality(Cursor, Cursor)

Cursor 클래스의 두 인스턴스가 같지 않은지 여부를 나타내는 값을 반환합니다.

명시적 인터페이스 구현

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

개체를 serialize합니다.

적용 대상

추가 정보