Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How To Determine If Form Is In Focus

In my application I would like the option to have it make a sound when something happens if the form is not in focus. (similar to how an instant messenger makes a sound when the window is not in focus).

I can make the sound ok, but just need to detect if the window is in focus, so how can I do this?


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How Do I Determine When A Form Loses Focus
My vb app opens an excel spreadsheet in a browser control by passing it a url similar to "c:apps est.xls".

When I have the spreadsheet open in my browser control, I cannot open another excel session outside of the application. I am also unable to copy/paste between my app and an additional spreadsheet when I start with an open excel spreadsheet before I run my app.

My solution has been to try to disable the browser control when the form loses focus. I have tried the form_unload event, and the CallWindowProc lib, but nothing works.

I have spent countless hours on this and would appreciate any suggestions.

Determine Which Form In Porject Has Focus.
Hey all. I'm doing a fairly complicated hooking procedure in an attempt to make a vscrollbar scroll when the mousewheel is scrolled. At one point I iterate through all forms in my project, and then iterate through each object to determing if the mouse of over a scrollable control. I just need to figure out if the current form in the iteration is the one with focus. That way I can know to look at the controls on that form, but I can't find a property like form1.activecontrol that applies to forms (for example:

for each frmForms in vb.forms
next frmforms

but getcurrentform doesn't exist....I'm looking for something similar - i'm not sure if I'm explaining it clearly....

How To Determine If A Form Has Lost Focus
I have search the forum for the answer.. but now i am more confused.

API.. looks strange. and the other method (getWindow.. getfocus)
don`t seem to work..
Pls help

Determine Where Focus Came From?
I have two controls on a form, and then a toolbar.

When the delete button is hit on the toolbar I want to be able to determine which control previously had focus, or where focus came from.

Easy way to do this?

Determine Which Control Has Focus
I have 2 text boxes and a command button; text1, text2 and cmd1.

Let's say text2 has the focus. Now, when I press cmd1, I need to determine which of the two text boxes HAD the focus when I clicked. I need this because I am going to add some text to the box that had the focus when the button was pressed.

Is there an easy way to determine this or am I going to have to set a flag on the 'GotFocus' and 'LostFocus' events of the text boxes?


Determine Which Control Is Getting The Focus
Is there a way to determine which control will be receiving the focus.

I have 2 text boxes; text1 and text2. Text1 currently has the focus. I have a breakpoint set in Text1.LostFocus(). As the program is running, I click on Text2. My breakpoint kicks in since Text1 will lose focus. At this point in the code, is there a way to determine what control has been pressed (what control will get the focus).


How To Determine What Control Has Focus
How can I determine what object on my Windows Form has focus? I have a menu option that displays the FontDialog and I want to apply the selections made from the FontDialog to the text box that the user was in when they selected the menu option.

How To Determine What Control Has Focus
Is there an easy way to check to see what control on a form has focus and lost focus?


I have a form with 10 textboxes.

in each textbox "GotFocus" event I have this code..
(keep in mind the "text." name changes in each event)

VB Code:
text.backcolor = vbreddoevents

and in each textbox "LostFocus" event I have this code...

VB Code:
text.backcolor = vbwhitedoevents

I would like to have 2 events like ControlGotFoucs and ControlLostFocus and use some type of case statment (or something else) to change the backcolor for the controls...

Is this possible or do I need to code each and every controls events?

Thanks for the info,

Determine Which Control Has Focus
Background: I am developing an application that has an RichTextBox, 2 TextBoxes, and a DBGrid on the same form.

Problem: I would like to be able to set up a test to determine which of the above controls has focus at any given point in time. Then, depending on which control has focus, the application will procede accordingly.

Any suggestions will be welcome.


Determine Which Control Has Focus
Background: I am developing an application that has an RichTextBox, 2 TextBoxes, and a DBGrid on the same form.

Problem: I would like to be able to set up a test to determine which of the above controls has focus at any given point in time. Then, depending on which control has focus, the application will procede accordingly.

Any suggestions will be welcome.


How To Determine If Vb Function Got Focus
I need to know how I can determine if a user clicked over to another program and then came back to the vb program or if the function got focus from a call within the program. I am noticing that the got focus event gets called either way and need to set a flag based on how the got focus event was called


Determine Which Control Has Focus
Background: I am developing an application that has a RichTextBox, 2 TextBoxes, and a DBGrid on the same form.

Problem: I would like to be able to set up a test to determine which of the above controls has focus at any given point in time. Then, depending on which control has focus, the application will procede accordingly.

Any suggestions will be welcome.


Determine If Text Box Has Focus
Is there a way in VB 6 to determine if a textbox has focus?

How To Determine Which Control Has Got The Focus
Hi all,
I did not find anything here, neither in my VB Books...

Form1: I would like to get the name of the object that has got the focus actually to update the value.

I have got a value in my "tempval" variable. Depending on the focused object this should be updated

-> focused.text = tempval

Any hint on that?



>>>>>> Bugs will appear in one part of a working program when another 'unrelated' part is modified <<<<<

How To Determine Which Textbox Has Focus?
I have a form with a few textboxes. How do I determine which textbox has the focus upon clicking a command button?

Opening A Form But Not Give It The Focus (or Quick Tell Me Wich Form Has The Focus)
Opening a form but not give it the focus (or quick tell me wich form has the focus). Is this possible??

Determine Control That Previously Had Focus, How?
Dear all.

On a Form . . .

The forms .Activecontrol can tell which control presently has focus but
how do we determine which control Previously had focus?

any ideas?


Determine Control That Previously Had Focus, How?

I tried the code below as I need to reset the focus on the last control (textbox) if the data check fails was invalid.

Sadly it doesn't work. Can you help?

****START CODE****

Private mctlLastFocus As Control

Private Sub TextBox_LostFocus(index as integer)

Set mctlLastFocus = Me.TextBox(index)

End Sub

Private Sub TextBox_GotFocus(index as integer)

If chkData(mctlLastFocus) = False then
end if

End Sub

****END CODE****

How To Determine How The Got Focus Event Was Fired
I am having problems with the got focus event. I need to know if the user clicked another running application for example the vb code is running and then they click and browse the net for a while and then click back to the vb program and the got focus event is fired or if it is fired from within the program by a call to the function that contains it?

Here's A Challenge! How To Determine What Control You've Lost Focus From.
I just lost focus from a control to another control...
How is it possible to keep a record of the control's object name that you've just lost focus from?

This is in line with my previous post about trapping CTRL/V in a textbox control.

If I want to paste text from one form into another form, across multiple textbox controls, I need to programmatically control where the line ends and which textbox receives the text data. This I have under control, but the challenge is to know which textbox to paste stuff into if you've lost focus from a textbox into a form.

In otherwords, I have a system of automatically pasting text from one form to another form, but the receiving form, has many frames with many textboxes. How can I tell VB that I want to paste text data into a given textbox that I just left to get the data to paste into!? If you know what I mean.


Determine The Control With Focus When Selected By The Mouse
Hi all,

How do I detemine which control has the focus if selected by the mouse?

I can use the Form_KeyUp event and check that keycode = vbKeyTab to see whether a user has tabbed to a control, but I want to be able to run some code if a user clicks on a control (textbox mainly). The mousedown event applies to individual controls and I don't want to have to include code for every mousedown event for every control. Is there an easy way to do this, or maybe via WINAPI?


Please Help... How I Can Validate Or Determine Which Textbox Is The Current Focus?
How can i determine the current focus on the text box..?

please help thank you...

How To Give Focus To Activex Component On Form Focus?
Using the Reflections ActiveX component (Reflections is a popular Terminal Editor for connecting with old Alpha/VMS servers), I have a Form with this internal terminal editor ActiveX that obviously needs to have focus to type in.

I've tried setting Form_GotFocus and Form_Click to give focus to the activex component but to no avail. The only thing that works is if I set Form_Repaint to give focus, then it works fine. But repaint causes the window to constantly try to bring itself in front of other Microsoft apps like Word and Outlook and other VB apps when I drag them in front of it. And it keeps flashing in the task bar when I move something non-MS in front of it.

Is there a better way to keep focus on the activex terminal session when the form gets focus without using repaint?

Form Got Focus Or Lost Focus Don't Work
Hi, I have a form that I can't get the Lost Focus or Got Focus events to fire, would anybody know why?

Here is what I am trying to accomplish. I have an .exe vb6 application(MainApp) that opens another .exe vb6(ChildApp) application using the shell command. The main application has a list view with a bunch of records. The ChildApp is used to Insert, Delete or UPdate records from the MainApp. So when an Insert, Update or Delete take place on the Child App, I'd like to refresh the listview on the MainApp because the records have changed. How can I accomplish this? Is there a way to call the form in the Main Application from the Child Application even they are 2 different .exe files? I really need help on this please.

Determine If A Form Is Loaded Without Triggering The Form_Load Event Of That Form
Say you have a form, Form2 that can be called directly from a menu or alternatively from another form, Form1 (in this case it is called modally with Form1 as the owner of Form2).

In the Form_Load event of Form2 I want to determine where its been called from - in particular, if it has been called from Form1.

The following have been tried..

1) Querying Form1.Visible - It seems to attempt to load Form1 (obviously to poll this property) and although it does not show the form it does run part the Form_Load event of Form1 - which I don't want - I simply want to know if it's loaded or not.

2) Querying Me.Owner/Parent - No such properties.

3) "IsNull (Form1)" always returns False.
4) "Form1 Is Nothing" always returns False.

Any ideas? (other than declaring global variables to track them)

P/s - I suppose this is a wake-up call about the programming slackness inadvertently encouraged by the non-strictness of VB, as other truly object-oriented languages such as C++ would no doubt require you to create, manage and destroy individual instances of all objects loaded into memory at run time - including Forms thereby making problems such as this very intuitive to solve.

Refresh A Form Not In Focus From A Form That Is In Focus
When in a program with mulitple forms, I would like to refresh a form that is not currently in focus from a form that is currently in focus.

I have a parent form that contains status information. I call a child form to change information that will affect the satus information display.

Currently I go back to the parent that was not in focus, and perform and perform a manual refresh, via a command button which changes the entries in the status line.

All variables in a common module and declared as public.

What instruction process can I use to change information on the parent form when changes are made on the child form.

How To Determine What Form Called Current Form.
I have to think this would be fairly simple but I wasn't able to find it in the archives.

Is there an API call or some type of property that can tell me what form called/displayed the current form?

Form1 ------>Form3---------> Form4

Form2------->Form3---------> Form4 ---------> Form5

If I'm in Form4, how can I tell that it was called/displayed via Form1 to Form3 to Form4 as opposed to Form2 to Form3 to Form4?

I'm using "Form3.Show vbModal" in Form1 to show the Form3.
I'm using "Form4.Show vbModal" in Form3 to show the Form4.

While in Form4, I'd like to know what forms were accessed to get there. I don't want to keep track of the forms using global variables because the forms may drill down to any number of levels. (Form5, 6, etc)


How Can I Determine The Form Name? On A Multiple Form Prog
  i've created an aplication using a template in vb6.0 - it consists of a program that contains Multiple forms and a menu. On the menu file there is a "new document" option witch points out to the following sub:

Private Sub LoadNewDoc()
    Dim frmD As frmDocument
    Static lDocumentCount As Long
    lDocumentCount = lDocumentCount + 1
    'Set frmD = New frmDocument
    'frmD.Caption = "Documento " & lDocumentCount
End Sub

 Supose i'm runnig the program and i already have 2 or 3 forms open, how would i know the name for each form?

i've been using the form name that appears on the design time (frmDocument).., but when i run the prog and make a call to an object (via code) inside the form a new window oppens ("frmDocument") with a new form , with nothing related ...

Determine Focus Through "activecontrol" In EVB
What is the syntax to determine the focus of an item using the "activecontrol" property or any other method for that matter?

Old Problem, Still No Solution? (modal Form Losing Focus When Parent Form Is Minimize
Hi everyone,

I have a problem with modal forms that's very easy to reproduce, and
practically locks up the application:

When closing Form1 I display a modal from (Form2), more or less to
the user if he's sure, etc. That works fine if Form1 is in normal
state and visible.
If I minimize Form1 in the windows Taskbar before closing it using the
system menu, Form2 appears, but is grayed and cannot receive mouse or
keyboard input. Because Form2 is displayed and modal, I cannot do
else with the application. As far as the user is concerned, it's dead

Form2 does not receive a Deactivate or LostFocus event, where I could
possible "repair" things.

Cheers, Marek

Once Form Opened, How To Shift Back Focus On Sheet While Form Is Still Open?

Once I run my macro and my form is opened, the focus is entirely on the form and I cant select my excel workbook( or any workbook for that matter).

Is there any way that my macro is still runnin, i.e. form is still open (maybe a minimize option..) while i can select and change some values in my workbook..

I tried the myworksheet.activate but it doesnt solve the problem. Any help?


Show A Form On Top Of Another Form, But Keep Focus On The Lower Form?
I've attached a picture of a scheduling section for my applicaiton. The Tooltip window is a seperate form with transparency and no border. I would like the form to show on top of the scheduling form as in the screenshot, but I want the focus to remain on the lower form.

I have seen code somewhere that does this but I can't seem to find it anywhere?

How To Determine If MDI Form Has Any Child Form
Hi all,
When all child forms closed, the toolbar need to be hidden in the MDI form. Can anyone please tell me how to promatically determine if no child forms exist everytime when a user closes a child form.

Thanks and appreciated.

Determine Which Form Opened A Form?
Is there a way to determine which form opened a form? I know if Microsoft Access you use the OpenArgs of the docmd.openform method, but I can't find anything similiar in VB.

I have a form that can be opened up by several different forms, and when it is closed, I want it to go back to the form that opened it, so I need to know which one it was!!



Determine If Form Is Open
Does anyone know how to determine if an Access form is open from within the vba module? From within my subroutine, I want to give a message and end if the user does not have a specific form open.

Determine How Form Was Shown
I have a bunch of forms shown all at once and at certain points in time I want to be able to determine which ones are Modal and Modeless... does anyone know how I can do this?


How Do I Determine If The Mouse Is Within A Form

How will i determine if the mouse is within a form or not? Ive been trying to somehow use the cursor position. Any ideas?

How To Determine If That Form Is Already Loaded?
any help regarding this?
i'm expecting boolean data type to determine, is it possible?

How Can I Determine The Height Of Form Within IE?
I have a custom toolband that loads from within IE. I have a scrollbar control that I got from VbAccelerator which works fine.

This is the problem, when IE is resized the scrollbar should be recalculated but how do I determine what the IE window new size is?

Does that make sense??

Determine If A Form Is Open Or Not
How do I write an if statement that checks to see if a form is open or not?

I tried this and it doesn't seem to work.

If frmRandomForm.WindowState = 0 Then
'Do something
End If

How To Determine If Form Is Modal?
How do I figure out if my form is modal or not?

On Unloading a form, f it's modal, I'd like to do thing A. If not, then do B.

I know I could set a variable to track if it's modal or not, but is there any property that could tell me this?


How To Determine The User Is Not Using The Form
Hi, VB Experts! Do anyof you know how to determine whether the user is using the form, or not?I mean I want to do is, that if the user didn't click on the form or set focus to the form in 5 minutes the FORM WILL load A msgbox, saying "Hey man you are not good."

ANy ideas?

Determine If A Form Is Open Or Not In VB.NET

Can anybody tell me how I determine whether a form (window) is open or not
in my VB.NET app?

Thanks in advance.

Best regards
Darren Logan BSc(Hons)
Development Engineer

Determine If A Form Is Loaded?
How do I determine if a form is loaded? I tried to use

if form.visible = true then
'code here
end if

but that caused the form's load sub routine to be executed and I can't have that. Someone out there have a good idea?

Getting Text To Show Highlights On Form Behind Form In Focus
Title sounds kind of funny. I'll see if I can explain better.

With my text editor, when I have the (Find/Replace) Form up, and I do a Find or Replace... I have it coded to "highlight" the text using .SelLength, however, it doesn't show the text as selected until I switch focus BACK to the main form (by clicking on it, or tabbing). When I click (or tab) back to the find box, the highlighting goes away.

For example, open up Notepad and paste some stuff in it, do a "Find", you'll see when it finds the text, it will be highlighted while the Find box is still in focus.

This is how I'd like my application to behave. Any ideas?

I'm using a RTB control.

No Access To Form Unless And Event Occurs On Form W/ Focus
How do I make it so a user cannot access the form that does not have focus unless an event occurs on the form with focus?

Determine Current Form In MDI App (RESOLVED)
Hello everybody

I want to determine which is the current (active) child form in an MDI application. Then I would like to update a status bar pane with the name of the form. The hard part is first one. How can I go about?

thx, in advance

George Papadopoulos

Can We Determine Image Coordinates In Form?
I have an image and it has three parts divide like contact,help and Phone.

if it is in Html we can determine where user clicks accorging to its Coordinates.

Can we do it in VB form?Like if I load same image in form How to recognize coordinates?


Easy? But I Don't Know How To Determine If A Form Exists
I need to know the method or simple command to call to find out if a form exist in my project. I need to know so that if it exist I can manipulate it, close it, replace it with another window by code.

Thanks in advance

Copyright 2005-08, All rights reserved