Control.Focused 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得指示控制項是否擁有輸入焦點的值。
public:
virtual property bool Focused { bool get(); };
C#
[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 停用 。 此範例會要求您具有 Form 名為 的 ,以及名為 menuItemEdit
和 menuItemEditInsertCustomerInfo
的兩 MenuItem 個 TextBox textBox1
物件。
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;
}
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;
}
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 屬性來擴充基底實作。 否則,您必須提供所有實作。
產品 | 版本 |
---|---|
.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 |