Control.Cursor 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當滑鼠指標位於控制器上時,會顯示或設定游標。
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 ComboBox 。 範例還設定了組合框的 Cursor 屬性,當 Cursors.Hand 滑鼠指標位於下拉按鈕上時,游標會顯示。 這條程式碼要求你必須有 Form 帶有 a ComboBox 的 a。
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
備註
將 a Cursor 指派給 Cursor 控制項的屬性,以改變滑鼠指標在控制項上方時顯示的游標。 要暫時更改應用程式中所有控制項的滑鼠游標,請設定該 Cursor.Current 屬性。 通常在填ComboBox入檔案、儲存檔案或載入檔案時,你會把屬性設Cursor.Current為等待游標。
該 Cursor 物業為環境性物業。 環境屬性是指若未設定,將從父控制項取得的控制屬性。 例如,a Button 預設會與其父Form節點相同BackColor。 欲了解更多環境特性資訊,請參閱職業Control或AmbientProperties職業概述。
給繼承者的注意事項
在導出類別中覆寫該 Cursor 屬性時,請使用基底類別的 Cursor 特性來擴充基底實作。 否則,你必須提供所有的實作。 您不必同時覆寫 get 該屬性及其 set 方法 Cursor ;必要時只需覆寫其中一項。