?
Solved

How to check if a form has the focus?

Posted on 2009-07-01
3
Medium Priority
?
978 Views
Last Modified: 2013-11-07
Hello,

I use vb.net 1.1 and have 3 forms called respectivelly f1, f2 and f3.

I use to have the following code working. I have no idea why it has ceased to work. All that is different is the PC the software has been installed on.

if f1.focussed then
...
elseif f2.focussed then
...
elseif f3.focussed then
...
end if

for some reason I do not understand, focussed always returns false regardless of the focus state.

Is there another way to identify if a form has the focus?

Thanks
0
Comment
Question by:etiennedemers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
jinal earned 1200 total points
ID: 24759801
If form contain many control then when form get focus its defalut control get focus so form.focused return false.

Instread of that try to use ActiveForm property to get currelty active form of application.
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 800 total points
ID: 24760033
Extending jinal's answer...

If "f1" is a variable name (an instance of a form) then use:

    If Form.ActiveForm Is f1 Then
        ...

If "f1" is the actual type of the form then use:

    If TypeOf Form.ActiveForm Is f1 Then
        ..
0
 

Author Closing Comment

by:etiennedemers
ID: 31599035
Thanks guys.
0

Featured Post

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question