Testing for focus on a form

  • Thread starter Thread starter copyco
  • Start date Start date
C

copyco

I want to be able to test if my app's form has focus, (ie: not in
background, behind other windows). How can I do this? I tried the
Me.Focused, but that doesn't work. I think it's because a control
within the form actually has focus, so the Me.Focused would return
false. Thanks!
 
Sounds good, but I don't seem to have that property. It doesn't come up
in the help search either. This is a Windows App, not a Web App.
Perhaps there's a difference.
 
it's a property of System.Windows.Form.Control which is one of the base
classes of Form...




.NET Framework Class Library

Control.ContainsFocus Property
See Also
Control Class | Control Members | System.Windows.Forms Namespace | CanFocus
| Focus | Focused | CanSelect

Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server
family

Language
a.. C#

b.. C++

c.. JScript

d.. Visual Basic

e.. Show All
Gets a value indicating whether the control, or one of its child controls,
currently has the input focus.

[Visual Basic]
Public ReadOnly Property ContainsFocus As Boolean[C#]
public bool ContainsFocus {get;}[C++]
public: __property bool get_ContainsFocus();[JScript]
public function get ContainsFocus() : Boolean;Property Value
true if the control or one of its child controls currently has the input
focus; otherwise, false.

Remarks
You can use this property to determine whether a control or any of the
controls contained within it has the input focus. To determine whether the
control has focus, regardless of whether any of its child controls have
focus, use the Focused property. To give a control the input focus, use the
Focus or Select methods.

Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server
family

See Also
Control Class | Control Members | System.Windows.Forms Namespace | CanFocus
| Focus | Focused | CanSelect


----------------------------------------------------------------------------
----

Send comments on this topic.

© 2001 Microsoft Corporation. All rights reserved.
 
Is there some sort of Imports that I need to include in my project to
get this property? When I type Me. ContainsFocus is not available.

Dominique said:
it's a property of System.Windows.Form.Control which is one of the base
classes of Form...




.NET Framework Class Library

Control.ContainsFocus Property
See Also
Control Class | Control Members | System.Windows.Forms Namespace | CanFocus
| Focus | Focused | CanSelect

Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server
family

Language
a.. C#

b.. C++

c.. JScript

d.. Visual Basic

e.. Show All
Gets a value indicating whether the control, or one of its child controls,
currently has the input focus.

[Visual Basic]
Public ReadOnly Property ContainsFocus As Boolean[C#]
public bool ContainsFocus {get;}[C++]
public: __property bool get_ContainsFocus();[JScript]
public function get ContainsFocus() : Boolean;Property Value
true if the control or one of its child controls currently has the input
focus; otherwise, false.

Remarks
You can use this property to determine whether a control or any of the
controls contained within it has the input focus. To determine whether the
control has focus, regardless of whether any of its child controls have
focus, use the Focused property. To give a control the input focus, use the
Focus or Select methods.

Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server
family

See Also
Control Class | Control Members | System.Windows.Forms Namespace | CanFocus
| Focus | Focused | CanSelect


----------------------------------------------------------------------------
----

Send comments on this topic.

© 2001 Microsoft Corporation. All rights reserved.





Sounds good, but I don't seem to have that property. It doesn't come up
in the help search either. This is a Windows App, not a Web App.
Perhaps there's a difference.

Dominique Vandensteen wrote:
 
Ah, nevermind. It isn't available via intelli-sense. You have to type
it in manually. How strange. Thanks for the help.
Is there some sort of Imports that I need to include in my project to
get this property? When I type Me. ContainsFocus is not available.

Dominique said:
it's a property of System.Windows.Form.Control which is one of the base
classes of Form...




.NET Framework Class Library

Control.ContainsFocus Property
See Also
Control Class | Control Members | System.Windows.Forms Namespace |
CanFocus
| Focus | Focused | CanSelect

Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition,
Windows
2000, Windows XP Home Edition, Windows XP Professional, Windows .NET
Server
family

Language
a.. C#

b.. C++

c.. JScript

d.. Visual Basic

e.. Show All
Gets a value indicating whether the control, or one of its child
controls,
currently has the input focus.

[Visual Basic]
Public ReadOnly Property ContainsFocus As Boolean[C#]
public bool ContainsFocus {get;}[C++]
public: __property bool get_ContainsFocus();[JScript]
public function get ContainsFocus() : Boolean;Property Value
true if the control or one of its child controls currently has the input
focus; otherwise, false.

Remarks
You can use this property to determine whether a control or any of the
controls contained within it has the input focus. To determine whether
the
control has focus, regardless of whether any of its child controls have
focus, use the Focused property. To give a control the input focus,
use the
Focus or Select methods.

Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition,
Windows
2000, Windows XP Home Edition, Windows XP Professional, Windows .NET
Server
family

See Also
Control Class | Control Members | System.Windows.Forms Namespace |
CanFocus
| Focus | Focused | CanSelect


----------------------------------------------------------------------------

----

Send comments on this topic.

© 2001 Microsoft Corporation. All rights reserved.





Sounds good, but I don't seem to have that property. It doesn't come up
in the help search either. This is a Windows App, not a Web App.
Perhaps there's a difference.

Dominique Vandensteen wrote:


try ContainsFocus property

dominique



I want to be able to test if my app's form has focus, (ie: not in
background, behind other windows). How can I do this? I tried the
Me.Focused, but that doesn't work. I think it's because a control
within the form actually has focus, so the Me.Focused would return
false. Thanks!
 
* copyco said:
Ah, nevermind. It isn't available via intelli-sense. You have to
type it in manually. How strange. Thanks for the help.

Are you sure you enabled the option to show advanced members in the
IDE's settings?
 
* copyco said:
Nope, I sure haven't. Where is this setting?

I am not sure if it will help in this case.

You can show advanced members in the code editor with the "Hide advanced
members" option under "Tools" -> "Options" -> "Text Editor" -> "Basic"
-> "General".
 
Back
Top