Control.Focused 屬性

定義

取得指示控制項是否擁有輸入焦點的值。Gets a value indicating whether the control has input focus.

public:
 virtual property bool Focused { bool get(); };
[System.ComponentModel.Browsable(false)]
public virtual bool Focused { get; }
member this.Focused : bool
Public Overridable ReadOnly Property Focused As Boolean

屬性值

如果焦點在控制項,則為 true,否則為 falsetrue if the control has focus; otherwise, false.

屬性

範例

如果 TextBox 沒有焦點,下列程式碼範例會停用 MenuItemThe following code example disables a MenuItem if a TextBox does not have focus. 這個範例需要有一個名為 textBox1 TextBoxForm,以及兩個名為 menuItemEditmenuItemEditInsertCustomerInfoMenuItem 物件。This example requires that you have a Form with a TextBox named textBox1 and two MenuItem objects named menuItemEdit and menuItemEditInsertCustomerInfo.

private:
   void menuItemEdit_Popup( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      // Disable the menu item if the text box does not have focus.
      this->menuItemEditInsertCustomerInfo->Enabled = this->textBox1->Focused;
   }
private void menuItemEdit_Popup(object sender, EventArgs e)
{
   // Disable the menu item if the text box does not have focus.
   this.menuItemEditInsertCustomerInfo.Enabled = this.textBox1.Focused;
}
Private Sub menuItemEdit_Popup(sender As Object, _
  e As EventArgs) Handles menuItemEdit.Popup
   ' Disable the menu item if the text box does not have focus.
   Me.menuItemEditInsertCustomerInfo.Enabled = Me.textBox1.Focused
End Sub

給繼承者的注意事項

覆寫衍生類別中的 Focused 屬性時,請使用基類的 Focused 屬性來擴充基底的執行。When overriding the Focused property in a derived class, use the base class's Focused property to extend the base implementation. 否則,您必須提供所有的實作為。Otherwise, you must provide all the implementation.

適用於

另請參閱