467,136 Members | 1,378 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,136 developers. It's quick & easy.

Testing for focus on a form

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!
Nov 20 '05 #1
  • viewed: 1617
Share:
8 Replies
try ContainsFocus property

dominique

"copyco" <co****@anon.com> wrote in message
news:fn********************@newssvr11.news.prodigy .com...
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!

Nov 20 '05 #2
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

"copyco" <co****@anon.com> wrote in message
news:fn********************@newssvr11.news.prodigy .com...
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!


Nov 20 '05 #3
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.

"copyco" <co****@anon.com> wrote in message
news:lF**************@newssvr22.news.prodigy.com.. .
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

"copyco" <co****@anon.com> wrote in message
news:fn********************@newssvr11.news.prodigy .com...
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!


Nov 20 '05 #4
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 Vandensteen wrote:
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.

"copyco" <co****@anon.com> wrote in message
news:lF**************@newssvr22.news.prodigy.com.. .
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

"copyco" <co****@anon.com> wrote in message
news:fn********************@newssvr11.news.prod igy.com...
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!


Nov 20 '05 #5
Ah, nevermind. It isn't available via intelli-sense. You have to type
it in manually. How strange. Thanks for the help.

copyco wrote:
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 Vandensteen wrote:
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.

"copyco" <co****@anon.com> wrote in message
news:lF**************@newssvr22.news.prodigy.com.. .
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

"copyco" <co****@anon.com> wrote in message
news:fn********************@newssvr11.news.prodigy .com...
> 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!


Nov 20 '05 #6
* copyco <co****@anon.com> scripsit:
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?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
Nope, I sure haven't. Where is this setting?
Herfried K. Wagner [MVP] wrote:
* copyco <co****@anon.com> scripsit:
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?

Nov 20 '05 #8
* copyco <co****@anon.com> scripsit:
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".

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike Irwin | last post: by
reply views Thread by Jonathan Allen | last post: by
5 posts views Thread by tshad | last post: by
17 posts views Thread by Neil Ginsberg | last post: by
5 posts views Thread by Tosch | last post: by
7 posts views Thread by Ed Jay | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.