Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to check if a form has the focus?

Posted on 2009-07-01
3
Medium Priority
?
986 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

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 …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

604 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