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.

适用于

另请参阅