Control.Focused Property


获取一个值,该值指示控件是否有输入焦点。Gets a value indicating whether the control has input focus.

 virtual property bool Focused { bool get(); };
public virtual bool Focused { get; }
member this.Focused : bool
Public Overridable ReadOnly Property Focused As Boolean

Property Value


如果控件有焦点,则为 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.

   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

Notes to Inheritors

在派生类中重写 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.

Applies to

See also