Control.Cursor 屬性

定義

取得或設定滑鼠指標移至控制項上時顯示的游標。

C#
public virtual System.Windows.Forms.Cursor Cursor { get; set; }

屬性值

Cursor

Cursor,表示滑鼠指標移至控制項上方時所顯示的游標。

範例

下列程式碼範例會 ComboBox 填入使用者可用的邏輯磁片磁碟機。 此範例也會設定下拉式方塊的 Cursor 屬性,以便在 Cursors.Hand 滑鼠指標位於下拉式按鈕上方時顯示游標。 此程式碼需要您具有 FormComboBox

C#
private void Form1_Load(object sender, EventArgs e)
{
   // Display the hand cursor when the mouse pointer
   // is over the combo box drop-down button. 
   comboBox1.Cursor = Cursors.Hand;

   // Fill the combo box with all the logical 
   // drives available to the user.
   try
   {
      foreach(string logicalDrive in Environment.GetLogicalDrives() )
      {
         comboBox1.Items.Add(logicalDrive);
      }
   }
   catch(Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}

備註

Cursor將 指派給 Cursor 控制項的 屬性,以變更滑鼠指標在控制項上方時所顯示的游標。 若要暫時變更應用程式上所有控制項的滑鼠游標, Cursor.Current 請設定 屬性。 一般而言,您會在填入 ComboBox 或儲存或載入檔案時,將 Cursor.Current 屬性設定為等候游標。

屬性 Cursor 是環境屬性。 環境屬性是控制項屬性,如果未設定,則會從父控制項擷取。 例如, Button 預設會有與其父 Form 系相同的 BackColor 。 如需環境屬性的詳細資訊,請參閱 AmbientProperties 類別或類別概 Control 觀。

給繼承者的注意事項

在衍生類別中覆 Cursor 寫 屬性時,請使用基類的 Cursor 屬性來擴充基底實作。 否則,您必須提供所有實作。 您不需要同時覆寫 get 屬性的 Cursorset 方法;您可以視需要只覆寫一個。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另請參閱