• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 989
  • Last Modified:

How to check if a form has the focus?


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?

2 Solutions
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.
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
etiennedemersAuthor Commented:
Thanks guys.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now