Control.Cursor 屬性

定義

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

public:
 virtual property System::Windows::Forms::Cursor ^ Cursor { System::Windows::Forms::Cursor ^ get(); void set(System::Windows::Forms::Cursor ^ value); };
public virtual System.Windows.Forms.Cursor Cursor { get; set; }
member this.Cursor : System.Windows.Forms.Cursor with get, set
Public Overridable Property Cursor As Cursor

屬性值

Cursor

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

範例

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

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
      {
         IEnumerator^ myEnum = Environment::GetLogicalDrives()->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            String^ logicalDrive = safe_cast<String^>(myEnum->Current);
            comboBox1->Items->Add( logicalDrive );
         }
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( ex->Message );
      }
   }
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);
   }
}
Private Sub Form1_Load(sender As Object, _
  e As EventArgs) Handles MyBase.Load
   ' 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
      Dim logicalDrive As String
      For Each logicalDrive In  Environment.GetLogicalDrives()
         comboBox1.Items.Add(logicalDrive)
      Next logicalDrive
   Catch ex As Exception
      MessageBox.Show(ex.Message)
   End Try
End Sub

備註

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

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

給繼承者的注意事項

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

適用於

另請參閱