Proprietà Control.Cursor (System.Windows.Forms)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Proprietà Control.Cursor

Ottiene o imposta il cursore visualizzato quando il puntatore del mouse viene spostato sul controllo.

Spazio dei nomi: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Sintassi

Visual Basic - (Dichiarazione)
Public Overridable Property Cursor As Cursor
Visual Basic (Utilizzo)
Dim instance As Control
Dim value As Cursor

value = instance.Cursor

instance.Cursor = value
C#
public virtual Cursor Cursor { get; set; }
C++
public:
virtual property Cursor^ Cursor {
	Cursor^ get ();
	void set (Cursor^ value);
}
J#
/** @property */
public Cursor get_Cursor ()

/** @property */
public void set_Cursor (Cursor value)

JScript
public function get Cursor () : Cursor

public function set Cursor (value : Cursor)

Valore proprietà

Oggetto Cursor che rappresenta il cursore visualizzato quando il puntatore del mouse viene spostato sul controllo.
Note

Assegnare un oggetto Cursor alla proprietà Cursor del controllo per modificare l'aspetto del cursore quando il puntatore del mouse viene spostato sul controllo. Per modificare temporaneamente il cursore del mouse per tutti i controlli dell'applicazione, impostare la proprietà Cursor.Current. In genere, è preferibile impostare la proprietà Cursor.Current su un cursore di attesa per il cursore da visualizzare durante la compilazione di un ComboBox o il salvataggio o il caricamento di file.

La proprietà Cursor è una proprietà di ambiente. Una proprietà di ambiente è una proprietà di un controllo che, se non impostata, viene recuperata dal controllo padre. Per impostazione predefinita, a un controllo Button sarà associata, ad esempio, la stessa proprietà BackColor del controllo Form padre. Per ulteriori informazioni sulle proprietà di ambiente, vedere i cenni preliminari sulla classe AmbientProperties o sulla classe Control.

Note sull'ereditarietà: Quando si esegue l'override della proprietà Cursor in una classe derivata, utilizzare la proprietà Cursor della classe base per estendere l'implementazione base. In caso contrario, sarà necessario fornire l'intera implementazione. Non è necessario eseguire l'override di entrambi i metodi get e set della proprietà Cursor. È sufficiente eseguire l'override di uno soltanto di essi, se necessario.

Esempio

Nell'esempio di codice riportato di seguito un oggetto ComboBox viene completato con i dati relativi alle unità logiche disponibili dell'utente. Nell'esempio viene inoltre impostata la proprietà Cursors.Hand della casella combinata affinché venga visualizzato il cursore Cursor quando il puntatore del mouse viene spostato sul pulsante a discesa. Per eseguire questo codice è necessario che sia disponibile un oggetto Form con un oggetto ComboBox.

Visual Basic
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

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);
   }
}

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
      {
         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 );
      }
   }

J#
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.set_Cursor(Cursors.get_Hand());
    // Fill the combo box with all the logical 
    // drives available to the user.
    try {
        for (int iCtr = 0; iCtr < Environment.GetLogicalDrives().
            get_Length(); iCtr++) {
            String logicalDrive = Environment.GetLogicalDrives()[iCtr];
            comboBox1.get_Items().Add(logicalDrive);
        }
    }
    catch (System.Exception ex) {
        MessageBox.Show(ex.get_Message());
    }
} //Form1_Load

Protezione .NET Framework

  • UIPermission  per consentire alle sottofinestre protette di impostare il valore di questa proprietà. Enumerazione associata: UIPermissionWindow.SafeSubWindows
Piattaforme

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

Informazioni sulla versione

.NET Framework

Supportato in: 2.0 1.1 1.0
Vedere anche