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

屬性值

Boolean

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

屬性

範例

如果 沒有焦點, TextBox 下列程式碼範例會 MenuItem 停用 。 此範例會要求您具有 Form 名為 的 ,以及名為 menuItemEditmenuItemEditInsertCustomerInfo 的兩 MenuItemTextBox 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;
   }
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 屬性來擴充基底實作。 否則,您必須提供所有實作。

適用於

另請參閱