Control.Focused 属性

定义

获取一个值,该值指示控件是否有输入焦点。

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

属性值

如果控件有焦点,则为 true;否则为 false

属性

示例

下面的代码示例在 没有焦点时TextBox禁用 MenuItem 。 此示例要求具有 一个FormTextBox具有命名textBox1的 对象和两MenuItem个名为 和 menuItemEditInsertCustomerInfo的对象menuItemEdit

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 属性来扩展基实现。 否则,必须提供所有实现。

适用于

另请参阅