Cursors 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 Cursor 物件的集合供 Windows Form 應用程式使用。
public ref class Cursors sealed
public ref class Cursors abstract sealed
public sealed class Cursors
public static class Cursors
type Cursors = class
Public NotInheritable Class Cursors
Public Class Cursors
- 繼承
-
Cursors
範例
下列範例示範如何使用 Control.Cursor 屬性、 Cursor 類別和 Cursors 類別來變更滑鼠游標。 此範例會建立包含控制項、 Panel 控制項和 ListView 控制項的表單 ComboBox 。 ComboBox包含 類別提供 Cursors 的所有資料指標。 當使用者在 中 ComboBox 選取滑鼠游標時, Control.Cursor 屬性會設定為選取的資料指標,以更新 的資料 Panel 指標。 每次事件發生時, Control.CursorChanged 都會 ListView 更新 。
#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 ref 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 = gcnew System::Windows::Forms::ComboBox;
this->testPanel = gcnew System::Windows::Forms::Panel;
this->label1 = gcnew System::Windows::Forms::Label;
this->label2 = gcnew System::Windows::Forms::Label;
this->cursorEventViewer = gcnew System::Windows::Forms::ListView;
this->label3 = gcnew 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 = "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 = "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 = "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 += gcnew 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 += gcnew 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 );
array<System::Windows::Forms::Control^>^temp0 = {this->label3,this->cursorEventViewer,this->label2,this->label1,this->testPanel,this->cursorSelectionComboBox};
this->Controls->AddRange( temp0 );
this->Text = "Cursors Example";
// Add all the cursor types to the combobox.
System::Collections::IEnumerator^ myEnum = CursorList()->GetEnumerator();
while ( myEnum->MoveNext() )
{
System::Windows::Forms::Cursor^ cursor = safe_cast<System::Windows::Forms::Cursor^>(myEnum->Current);
cursorSelectionComboBox->Items->Add( cursor );
}
}
private:
array<System::Windows::Forms::Cursor^>^ CursorList()
{
// Make an array of all the types of cursors in Windows Forms.
array<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( "[{0}]: {1}", sender->GetType(), "Cursor changed" );
// Record this event in the list view.
this->cursorEventViewer->Items->Add( cursorEvent );
}
};
}
[STAThread]
int main()
{
Application::Run( gcnew MCursor::Form1 );
}
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);
}
}
}
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
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
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
End Namespace 'MCursor
下列範例會以正常大小和延展模式在表單上繪製指定的游標,其大小為兩倍。 這個範例假設您在呼叫 方法時,有 Form 和 Cursor 物件要傳入 方法。
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.
delete cursor;
}
}
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();
}
}
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
備註
Cursor此類別中的某些物件可能會採用與所述的物件不同的外觀。 使用者可以藉由調整作業系統中的滑鼠指標設定來變更游標外觀。 移動流覽和沒有移動游標是靜態的,而且無法由作業系統變更。
移動流覽和移動游標不會在滑鼠滾輪作業期間使用。 視視窗可捲動的方向而定,當按一下滑鼠滾輪時,游標會變更為適當的無移動游標。 游標接著會在移動滑鼠時變更為適當的移動流覽游標。
屬性
AppStarting |
取得應用程式啟動時出現的游標。 |
Arrow |
取得箭號游標。 |
Cross |
取得十字型游標。 |
Default |
取得預設游標,通常為箭號游標。 |
Hand |
取得手狀游標,通常在游標停留在 Web 連結上方時使用。 |
Help |
取得由箭號和問號組成的說明游標。 |
HSplit |
取得當滑鼠位在水平分割列上時出現的游標。 |
IBeam |
取得 I 型游標,這個游標用來顯示當按一下滑鼠時文字游標出現的位置。 |
No |
取得指示目前作業的特定區域無效的游標。 |
NoMove2D |
取得當滑鼠不移動,但視窗可以水平和垂直方向捲動時,滑鼠滾輪作業期間出現的游標。 |
NoMoveHoriz |
取得當滑鼠不移動,但視窗可以水平方向捲動時,滑鼠滾輪作業期間出現的游標。 |
NoMoveVert |
取得當滑鼠不移動,但視窗可以垂直方向捲動時,滑鼠滾輪作業期間出現的游標。 |
PanEast |
取得當滑鼠移動,而且視窗可水平捲動至右方時,滑鼠滾輪作業期間出現的游標。 |
PanNE |
取得當滑鼠移動,而且視窗可水平和垂直捲動至上方和右方時,滑鼠滾輪作業期間出現的游標。 |
PanNorth |
取得當滑鼠移動,而且視窗可垂直捲動至上方時,滑鼠滾輪作業期間出現的游標。 |
PanNW |
取得當滑鼠移動,而且視窗可水平和垂直捲動至上方和左方時,滑鼠滾輪作業期間出現的游標。 |
PanSE |
取得當滑鼠移動,而且視窗可水平和垂直捲動至下方和右方時,滑鼠滾輪作業期間出現的游標。 |
PanSouth |
取得當滑鼠移動,而且視窗可垂直捲動至下方時,滑鼠滾輪作業期間出現的游標。 |
PanSW |
取得當滑鼠移動,而且視窗可水平和垂直捲動至下方和左方時,滑鼠滾輪作業期間出現的游標。 |
PanWest |
取得當滑鼠移動而且視窗可水平捲動至左方時,滑鼠滾輪作業期間出現的游標。 |
SizeAll |
取得四頭調整大小游標,它是由四個連結的箭號 (分別指向北、南、東和西) 所組成。 |
SizeNESW |
取得雙頭斜線 (東北/西南) 調整大小游標。 |
SizeNS |
取得雙頭垂直 (北/南) 調整大小游標。 |
SizeNWSE |
取得雙頭斜線 (西北/東南) 調整大小游標。 |
SizeWE |
取得雙頭水平 (西/東) 調整大小游標。 |
UpArrow |
取得向上箭號游標,通常用來辨認插入點。 |
VSplit |
取得當滑鼠位在垂直分割列上方時出現的游標。 |
WaitCursor |
取得等待游標,其形狀通常為沙漏形狀。 |