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の再描画は、BeginUpdateメソッドとEndUpdateメソッドを使用して抑制され、TreeViewがTreeNode オブジェクトを作成して描画する間、待機Cursorが表示されます。 この例では、アプリケーション ディレクトリに MyWait.cur という名前のカーソル ファイルが必要です。 また、Order オブジェクトのコレクションを保持でき、Formに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 カーソルが表示されます。 待機カーソルは、通常、プロセスが現在実行中であることをユーザーに通知するために使用されます。 ユーザーが待機するプロセスの例としては、ファイルを開いたり、ファイルを保存したり、 DataGrid、 ListBox 、 TreeView などのコントロールに大量のデータを入力したりする場合があります。
Control クラスから派生するすべてのコントロールには、Cursor プロパティがあります。 マウス ポインターがコントロールの境界内にあるときに表示されるカーソルを変更するには、コントロールのCursor プロパティにCursorを割り当てます。 または、Current プロパティにCursorを割り当てることで、アプリケーション レベルでカーソルを表示することもできます。 たとえば、アプリケーションの目的がテキスト ファイルを編集する場合は、 Current プロパティを Cursors.WaitCursor に設定して、ファイルの読み込み中または保存中に待機カーソルを表示して、マウス イベントが処理されないようにすることができます。 プロセスが完了したら、 Current プロパティをアプリケーションの Cursors.Default に設定して、各コントロールの種類に適切なカーソルを表示します。
注
Current プロパティをCursors.Default カーソルにリセットする前に Application.DoEvents を呼び出すと、アプリケーションはマウス イベントのリッスンを再開し、アプリケーション内の各コントロールの適切なCursorの表示を再開します。
カーソル オブジェクトは、既存の Cursorのハンドル、標準の Cursor ファイル、リソース、データ ストリームなど、複数のソースから作成できます。
注
Cursor クラスでは、アニメーション カーソル (.ani ファイル) や、白黒以外の色のカーソルはサポートされていません。
カーソルとして使用しているイメージが小さすぎる場合は、 DrawStretched メソッドを使用して、イメージがカーソルの境界を埋めるように強制できます。 Hide メソッドを呼び出してカーソルを一時的に非表示にし、Show メソッドを呼び出して復元できます。
.NET Framework 4.5.2 以降では、app.config ファイルに次のエントリが含まれている場合、システム DPI 設定に基づいて Cursor のサイズが変更されます。
<appSettings>
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>
コンストラクター
| 名前 | 説明 |
|---|---|
| Cursor(IntPtr) |
指定した Windows ハンドルから 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 クラスの 2 つのインスタンスが等しいかどうかを示す値を返します。 |
| Inequality(Cursor, Cursor) |
Cursor クラスの 2 つのインスタンスが等しくないかどうかを示す値を返します。 |
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
オブジェクトをシリアル化します。 |