Control.Cursor 屬性

定義

取得或設定滑鼠指標移至控制項上時顯示的游標。Gets or sets the cursor that is displayed when the mouse pointer is over the control.

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,表示滑鼠指標移至控制項上方時所顯示的游標。A Cursor that represents the cursor to display when the mouse pointer is over the control.

範例

下列程式碼範例會使用使用者可用的邏輯磁碟機來填滿 ComboBoxThe following code example fills a ComboBox with the user's available logical drives. 此範例也會設定下拉式方塊的 Cursor 屬性,因此當滑鼠指標位於下拉式按鈕上方時,就會顯示 Cursors.Hand 游標。The example also sets the combo box's Cursor property so the Cursors.Hand cursor is displayed when the mouse pointer is over the drop-down button. 這段程式碼需要您具有 ComboBoxFormThis code requires that you have a Form with a ComboBox on it.

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 屬性,以變更滑鼠指標停留在控制項上時所顯示的游標。Assign a Cursor to the Cursor property of the control to change the cursor displayed when the mouse pointer is over the control. 若要暫時變更應用程式上所有控制項的滑鼠游標,請設定 [Cursor.Current] 屬性。To temporarily change the mouse cursor for all controls on your application set the Cursor.Current property. 您通常會在填入 ComboBox 或儲存或載入檔案時,將 Cursor.Current 屬性設定為等待游標。Typically you would set the Cursor.Current property to a wait cursor when populating a ComboBox or saving or loading a file.

Cursor 屬性是環境屬性。The Cursor property is an ambient property. 環境屬性是控制項屬性,如果未設定,則會從父控制項抓取。An ambient property is a control property that, if not set, is retrieved from the parent control. 例如,Button 預設會有相同的 BackColor 做為其父系 FormFor example, a Button will have the same BackColor as its parent Form by default. 如需環境屬性的詳細資訊,請參閱 AmbientProperties 類別或 Control 類別的總覽。For more information about ambient properties, see the AmbientProperties class or the Control class overview.

給繼承者的注意事項

覆寫衍生類別中的 Cursor 屬性時,請使用基類的 Cursor 屬性來擴充基底的執行。When overriding the Cursor property in a derived class, use the base class's Cursor property to extend the base implementation. 否則,您必須提供所有的實作為。Otherwise, you must provide all the implementation. 您不需要覆寫 Cursor 屬性的 getset 方法;您可以視需要覆寫其中一個。You are not required to override both the get and set methods of the Cursor property; you can override only one if needed.

安全性

UIPermission
適用于安全子視窗設定此屬性值。for safe subwindows to set this property value. 相關聯的列舉: SafeSubWindowsAssociated enumeration: SafeSubWindows

適用於

另請參閱