Cursors クラス
Windows フォーム アプリケーションによって使用される Cursor オブジェクトのコレクションを提供します。
この型のすべてのメンバの一覧については、Cursors メンバ を参照してください。
System.Object
System.Windows.Forms.Cursors
NotInheritable Public Class Cursors
[C#]
public sealed class Cursors
[C++]
public __gc __sealed class Cursors
[JScript]
public class Cursors
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
このクラスの Cursor オブジェクトには、説明した外観とは異なる外観になるオブジェクトがあります。ユーザーのオペレーティング システムでマウス ポインタの設定を調整すると、カーソルの外観を変更できます。パン カーソルおよび静的カーソルは静的なカーソルであり、オペレーティング システムでは変更できません。
パン カーソルと静的カーソルは、マウス ホイールを操作しているときに使用します。マウス ホイールをクリックすると、ウィンドウをスクロールできる方向に応じて、カーソルが適切な静的カーソルに変わります。マウスを動かすと、カーソルは適切なパン カーソルに変わります。
使用例
[Visual Basic, C#, C++] Control.Cursor プロパティ、 Cursor クラスおよび Cursors クラスを使用して、マウス カーソルを変更する例を次に示します。この例では、 ComboBox コントロール、 Panel コントロール、および ListView コントロールを格納するフォームを作成します。 ComboBox には、 Cursors クラスによって提供されたすべてのカーソルが格納されています。ユーザーが ComboBox 内でマウス カーソルを選択すると、 Control.Cursor プロパティがそのカーソルに設定され、これによって Panel のカーソルが更新されます。 ListView は、 Control.CursorChanged イベントが発生するたびに更新されます。
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace MCursor
' Summary description for Form1.
Public NotInheritable Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents cursorSelectionComboBox As System.Windows.Forms.ComboBox
Friend WithEvents testPanel As System.Windows.Forms.Panel
Private label1 As System.Windows.Forms.Label
Private label2 As System.Windows.Forms.Label
Private cursorEventViewer As System.Windows.Forms.ListView
Private label3 As System.Windows.Forms.Label
<System.STAThread()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1)
End Sub 'Main
Public Sub New()
Me.cursorSelectionComboBox = New System.Windows.Forms.ComboBox
Me.testPanel = New System.Windows.Forms.Panel
Me.label1 = New System.Windows.Forms.Label
Me.label2 = New System.Windows.Forms.Label
Me.cursorEventViewer = New System.Windows.Forms.ListView
Me.label3 = New System.Windows.Forms.Label
' Select Cursor Label
Me.label2.Location = New System.Drawing.Point(24, 16)
Me.label2.Size = New System.Drawing.Size(80, 16)
Me.label2.Text = "Select cursor:" '
' Cursor Testing Panel Label
Me.label1.Location = New System.Drawing.Point(24, 80)
Me.label1.Size = New System.Drawing.Size(144, 23)
Me.label1.Text = "Cursor testing panel:"
' Cursor Changed Events Label
Me.label3.Location = New System.Drawing.Point(184, 16)
Me.label3.Size = New System.Drawing.Size(128, 16)
Me.label3.Text = "Cursor changed events:"
' Cursor Selection ComboBox
Me.cursorSelectionComboBox.Location = New System.Drawing.Point(24, 40)
Me.cursorSelectionComboBox.Size = New System.Drawing.Size(152, 21)
Me.cursorSelectionComboBox.TabIndex = 0
' Cursor Test Panel
Me.testPanel.BackColor = System.Drawing.SystemColors.ControlDark
Me.testPanel.Location = New System.Drawing.Point(24, 104)
Me.testPanel.Size = New System.Drawing.Size(152, 160)
' Cursor Event ListView
Me.cursorEventViewer.Location = New System.Drawing.Point(184, 40)
Me.cursorEventViewer.Size = New System.Drawing.Size(256, 224)
Me.cursorEventViewer.TabIndex = 4
Me.cursorEventViewer.View = System.Windows.Forms.View.List
' Set up how the form should be displayed and add the controls to the form.
Me.ClientSize = New System.Drawing.Size(456, 286)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.label3, _
Me.cursorEventViewer, Me.label2, Me.label1, _
Me.testPanel, Me.cursorSelectionComboBox})
Me.Text = "Cursors Example"
' Add all the cursor types to the combobox.
Dim cursor As Cursor
For Each cursor In CursorList()
cursorSelectionComboBox.Items.Add(cursor)
Next cursor
End Sub 'New
Private Function CursorList() As Cursor()
' Make an array of all the types of cursors in Windows Forms.
return New Cursor() {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}
End Function
Private Sub cursorSelectionComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cursorSelectionComboBox.SelectedIndexChanged
' Set the cursor in the test panel to be the selected cursor style.
testPanel.Cursor = CType(cursorSelectionComboBox.SelectedItem, Cursor)
End Sub
Private Sub testPanel_CursorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles testPanel.CursorChanged
' Build up a string containing the type of object sending the event, and the event.
Dim cursorEvent As String = String.Format("[{0}]: {1}", sender.GetType().ToString(), "Cursor changed")
' Records this event in the list view.
Me.cursorEventViewer.Items.Add(cursorEvent)
End Sub
End Class 'Form1
End Namespace 'MCursor
[C#]
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MCursor
{
public class Form1 : 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;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
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.Location = new System.Drawing.Point(24, 16);
this.label2.Size = new System.Drawing.Size(80, 16);
this.label2.Text = "Select cursor:";
// Cursor Testing Panel Label
this.label1.Location = new System.Drawing.Point(24, 80);
this.label1.Size = new System.Drawing.Size(144, 23);
this.label1.Text = "Cursor testing panel:";
// Cursor Changed Events Label
this.label3.Location = new System.Drawing.Point(184, 16);
this.label3.Size = new System.Drawing.Size(128, 16);
this.label3.Text = "Cursor changed events:";
// Cursor Selection ComboBox
this.cursorSelectionComboBox.Location = new System.Drawing.Point(24, 40);
this.cursorSelectionComboBox.Size = new System.Drawing.Size(152, 21);
this.cursorSelectionComboBox.TabIndex = 0;
this.cursorSelectionComboBox.SelectedIndexChanged +=
new System.EventHandler(this.cursorSelectionComboBox_SelectedIndexChanged);
// Cursor Test Panel
this.testPanel.BackColor = System.Drawing.SystemColors.ControlDark;
this.testPanel.Location = new System.Drawing.Point(24, 104);
this.testPanel.Size = new System.Drawing.Size(152, 160);
this.testPanel.CursorChanged += new System.EventHandler(this.testPanel_CursorChanged);
// Cursor Event ListView
this.cursorEventViewer.Location = new System.Drawing.Point(184, 40);
this.cursorEventViewer.Size = new 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 = new System.Drawing.Size(456, 286);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label3, this.cursorEventViewer,
this.label2, this.label1,
this.testPanel, this.cursorSelectionComboBox});
this.Text = "Cursors Example";
// Add all the cursor types to the combobox.
foreach (Cursor cursor in CursorList())
{
cursorSelectionComboBox.Items.Add(cursor);
}
}
private Cursor [] CursorList()
{
// Make an array of all the types of cursors in Windows Forms.
return new Cursor [] {
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};
}
private void cursorSelectionComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
// Set the cursor in the test panel to be the selected cursor style.
testPanel.Cursor = (Cursor)cursorSelectionComboBox.SelectedItem;
}
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.
this.cursorEventViewer.Items.Add(cursorEvent);
}
}
}
[C++]
#using <mscorlib.dll>
#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 __gc class Form1 : public System::Windows::Forms::Form {
private:
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;
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->Location = System::Drawing::Point(24, 16);
this->label2->Size = System::Drawing::Size(80, 16);
this->label2->Text = S"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 = S"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 = S"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 +=
new 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 += new 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);
System::Windows::Forms::Control* temp0 [] = {this->label3, this->cursorEventViewer,
this->label2, this->label1,
this->testPanel, this->cursorSelectionComboBox};
this->Controls->AddRange(temp0);
this->Text = S"Cursors Example";
// Add all the cursor types to the combobox.
System::Collections::IEnumerator* myEnum = CursorList()->GetEnumerator();
while (myEnum->MoveNext()) {
System::Windows::Forms::Cursor* cursor = __try_cast<System::Windows::Forms::Cursor*>(myEnum->Current);
cursorSelectionComboBox->Items->Add(cursor);
}
}
private:
System::Windows::Forms::Cursor* CursorList()[] {
// Make an array of all the types of cursors in Windows Forms.
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(S"[{0}]: {1}", sender->GetType(), S"Cursor changed");
// Record this event in the list view.
this->cursorEventViewer->Items->Add(cursorEvent);
}
};
}
[STAThread]
int main() {
Application::Run(new MCursor::Form1());
}
[Visual Basic, C#, C++] フォーム上に、指定されたカーソルをその通常サイズで描画し、次にストレッチ モードで 2 倍のサイズに描画する例を次に示します。この例は、 Form があり、呼び出されたときにメソッドに渡す Cursor オブジェクトがあることを前提にしています。
Private Sub DrawCursorsOnForm(cursor As Cursor)
' If the form's cursor is not the Hand cursor and the
' Current cursor is the Default, Draw the specified
' cursor on the form in normal size and twice normal size.
If (Not Me.Cursor.Equals(Cursors.Hand)) And _
Cursor.Current.Equals(Cursors.Default) Then
' Draw the cursor stretched.
Dim graphics As Graphics = Me.CreateGraphics()
Dim rectangle As New Rectangle(New Point(10, 10), _
New Size(cursor.Size.Width * 2, cursor.Size.Height * 2))
cursor.DrawStretched(graphics, rectangle)
' Draw the cursor in normal size.
rectangle.Location = New Point(rectangle.Width + _
rectangle.Location.X, rectangle.Height + rectangle.Location.Y)
rectangle.Size = cursor.Size
cursor.Draw(graphics, rectangle)
' Dispose of the cursor.
cursor.Dispose()
End If
End Sub
[C#]
private void DrawCursorsOnForm(Cursor cursor)
{
// If the form's cursor is not the Hand cursor and the
// Current cursor is the Default, Draw the specified
// cursor on the form in normal size and twice normal size.
if(this.Cursor != Cursors.Hand &
Cursor.Current == Cursors.Default)
{
// Draw the cursor stretched.
Graphics graphics = this.CreateGraphics();
Rectangle rectangle = new Rectangle(
new Point(10,10), new Size(cursor.Size.Width * 2,
cursor.Size.Height * 2));
cursor.DrawStretched(graphics, rectangle);
// Draw the cursor in normal size.
rectangle.Location = new Point(
rectangle.Width + rectangle.Location.X,
rectangle.Height + rectangle.Location.Y);
rectangle.Size = cursor.Size;
cursor.Draw(graphics, rectangle);
// Dispose of the cursor.
cursor.Dispose();
}
}
[C++]
private:
void DrawCursorsOnForm(System::Windows::Forms::Cursor* cursor) {
// If the form's cursor is not the Hand cursor and the
// Current cursor is the Default, Draw the specified
// cursor on the form in normal size and twice normal size.
if (this->Cursor != Cursors::Hand &&
System::Windows::Forms::Cursor::Current == Cursors::Default) {
// Draw the cursor stretched.
Graphics* graphics = this->CreateGraphics();
Rectangle rectangle = Rectangle( Point(10, 10), System::Drawing::Size(cursor->Size.Width * 2,
cursor->Size.Height * 2));
cursor->DrawStretched(graphics, rectangle);
// Draw the cursor in normal size.
rectangle.Location = Point(rectangle.Width + rectangle.Location.X,
rectangle.Height + rectangle.Location.Y);
rectangle.Size = cursor->Size;
cursor->Draw(graphics, rectangle);
// Dispose of the cursor.
cursor->Dispose();
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Windows.Forms
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)