Solved

How to check if a form has the focus?

Posted on 2009-07-01
3
971 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 300 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 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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