Control.Focused 屬性

定義

取得指示控制項是否擁有輸入焦點的值。

C#
[System.ComponentModel.Browsable(false)]
public virtual bool Focused { get; }

屬性值

Boolean

如果焦點在控制項,則為 true,否則為 false

屬性

範例

如果 沒有焦點, TextBox 下列程式碼範例會 MenuItem 停用 。 此範例會要求您具有 Form 名為 的 ,以及名為 menuItemEditmenuItemEditInsertCustomerInfo 的兩 MenuItemTextBox textBox1 物件。

C#
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;
}

給繼承者的注意事項

在衍生類別中覆 Focused 寫 屬性時,請使用基類的 Focused 屬性來擴充基底實作。 否則,您必須提供所有實作。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另請參閱