Solved

How to check if a form has the focus?

Posted on 2009-07-01
3
946 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
3 Comments
 
LVL 15

Accepted Solution

by:
jinal earned 300 total points
Comment Utility
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 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
Comment Utility
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
Comment Utility
Thanks guys.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How Can I fix my MouseHover Event? 14 26
Expando 4 33
Limiting string to two deciamls 18 30
Achieve json result 2 20
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now