Cursor 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
마우스 포인터를 그리는 데 사용되는 이미지를 나타냅니다.
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 메서드 및 EndUpdate 메서드를 BeginUpdate 사용하여 표시되지 않으며 개체를 만들고 그리는 동안 TreeView 대기 Cursor 가 TreeNode 표시됩니다. 이 예제에서는 애플리케이션 디렉터리에 이름이 지정된 MyWait.cur 커서 파일이 있어야 합니다. 또한 개체 컬렉션을 보유할 수 있고 컨트롤의 OrderTreeViewForm인스턴스를 만든 개체가 필요합니다.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 합니다. 또는 속성에 할당하여 애플리케이션 수준에서 커서를 Cursor 표시할 Current 수 있습니다. 예를 들어 애플리케이션의 목적이 텍스트 파일을 편집하는 경우 파일을 로드하거나 저장하여 마우스 이벤트가 처리되지 않도록 하는 동안 애플리케이션에 대한 대기 커서를 표시하도록 속성을 Cursors.WaitCursor 설정할 Current 수 있습니다. 프로세스가 완료되면 애플리케이션에 Current 대한 속성을 Cursors.Default 설정하여 각 컨트롤 형식에 적절한 커서를 표시합니다.
메모
속성을 커서로 Current 다시 설정하기 Cursors.Default 전에 호출 Application.DoEvents 하는 경우 애플리케이션은 마우스 이벤트 수신 대기를 다시 시작하고 애플리케이션의 각 컨트롤에 대한 적절한 Cursor 표시를 다시 시작합니다.
커서 개체는 기존 Cursor, 표준 Cursor 파일, 리소스 또는 데이터 스트림의 핸들과 같은 여러 원본에서 만들 수 있습니다.
메모
클래스는 Cursor 애니메이션된 커서(.ani 파일) 또는 흑백 이외의 색이 있는 커서를 지원하지 않습니다.
커서로 사용하는 이미지가 너무 작으면 메서드를 사용하여 DrawStretched 이미지가 커서의 범위를 채우도록 강제할 수 있습니다. 메서드를 호출하여 커서를 일시적으로 숨기고 메서드를 Hide 호출 Show 하여 복원할 수 있습니다.
.NET Framework 4.5.2 Cursor 부터는 app.config 파일에 다음 항목이 포함될 때 시스템 DPI 설정에 따라 크기가 조정됩니다.
<appSettings>
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>
생성자
| Name | Description |
|---|---|
| Cursor(IntPtr) |
지정된 Windows 핸들에서 클래스의 Cursor 새 인스턴스를 초기화합니다. |
| Cursor(Stream) |
지정된 데이터 스트림에서 클래스의 Cursor 새 인스턴스를 초기화합니다. |
| Cursor(String) |
지정된 파일에서 클래스의 Cursor 새 인스턴스를 초기화합니다. |
| Cursor(Type, String) |
지정된 리소스 유형을 사용하여 지정된 리소스에서 클래스의 Cursor 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| Clip |
커서의 클리핑 사각형을 나타내는 범위를 가져오거나 설정합니다. |
| Current |
마우스 커서를 나타내는 커서 개체를 가져오거나 설정합니다. |
| Handle |
커서의 핸들을 가져옵니다. |
| HotSpot |
커서 핫 스폿을 가져옵니다. |
| Position |
커서의 위치를 가져오거나 설정합니다. |
| Size |
커서 개체의 크기를 가져옵니다. |
| Tag |
에 대한 Cursor데이터가 들어 있는 개체를 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| 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문자열을 나타내는 사람이 읽을 수 있는 문자열을 검색합니다. |
연산자
| Name | Description |
|---|---|
| Equality(Cursor, Cursor) |
클래스의 Cursor 두 인스턴스가 같은지 여부를 나타내는 값을 반환합니다. |
| Inequality(Cursor, Cursor) |
클래스의 Cursor 두 인스턴스가 같지 않은지 여부를 나타내는 값을 반환합니다. |
명시적 인터페이스 구현
| Name | Description |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
개체를 직렬화합니다. |