Gets a value indicating whether the control has input focus.
[Visual Basic]
Public Overridable ReadOnly Property Focused As Boolean
[C#]
public virtual bool Focused {get;}
[C++]
public: __property virtual bool get_Focused();
[JScript]
public function get Focused() : Boolean; Property Value
true if the control has focus; otherwise, false.
Remarks
Notes to Inheritors: 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.
Example
[Visual Basic, C#, C++] The following example disables a MenuItem if a TextBox does not have focus. This example assumes you have a Form with a TextBox named textBox1 and two MenuItem objects named menuItemEdit and menuItemEditInsertCustomerInfo.
[Visual Basic]
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
[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;
}
[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;
}
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
See Also
Control Class | Control Members | System.Windows.Forms Namespace | CanFocus | Focus | CanSelect | ContainsFocus