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




About Get And Lost Focus Form Events


i have these simple project in Visual Basic 6:


Code:
Private Sub Form_GotFocus()
MsgBox "oi"
End Sub

Private Sub Form_LostFocus()
MsgBox "xau"
End Sub
if someone test these code, the gotfocus is only activated when the form is showed, but in other times isn't... and the lostfocus is ignored... can anyone explain to me why?
thanks




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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.

Form Lost Focus
Hello to all,

Is there any way to know if a form has lost its a focus in vb6?

Hope to get some idea on it.

Kevin.

Form Deactivate/lost Focus
i have 2 forms and on form1 ive the following code

Private Sub Command2_Click()
Load Form2
Form2.Show
MsgBox "ok"
End Sub

Private Sub Form_LostFocus()
Unload Me
End Sub


my purpose is to unload form1 when form1 loses focus. but in this case form 2 loads and gets focus, but form1 is not unloaded. strangely, if i take of the msgbox, it works as inteded.
thx

How To Set Form Blinking When It Lost Focus?
I just want set focus only one form. When it lost focus (click other form), I want to blinking title bar and set focus back to form.

best regards

How To Prevent That The Focus Of A Form Get Lost?
Hi,

anybody know how to refuse the User to go to a other open form or wherever he want?. I tried the "Trap the mouse" but unfortunatly it doesnt work with centered Forms because until now i dont know how to find the Top,Left position of a Form. It is in itself always 0,0 but on the screen it could be for example 500,200 or whatever.

Anybody got a idea?

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
Seahag

Get/lost Focus For Child Form
Using VB6, I have a child form that is automatically refreshing its data every 5 minutes. This results in the child form regaining focus whether I am in a different form/child form of the application or in a totally different application.

I want the refresh to work only if the child form has the focus. I have tried using GetFocus, LostFocus, Activate, and Deactivate, but LostFocus and Deactivate would not fire at all, even when moving to other forms/child forms of the application, let alone to other applications. I also tried using the GetForegroundWindow function, but it returned the hWnd of the mdi and not the child form, so I can not use that to determine my action.

Does anyone know of a way to check which child form has the focus or some other way to do this?
 
Thanks.
 


 

Make Form Stay On Top And Not Allow Lost Focus
I have a desktop shortcut that when clicked opens a exe in program files.
This exe opens a file on a usb drive and displays a message (in a form) to plug in
the usb. This form only has a ok button and when pressed it unloads the form.
How can i force the form to stay on top and not let any other programs get focus?

Form Exit Or Lost Focus Event
I want a form to be displayed that is not modal with a few buttons. If the user clicks on any other form, a different app, taskbar etc, then the form closes - sort of like how a drop down list disappears when it loses focus.

How do I do it? The form Lose Focus event never seems to fire.

Dialog Form Lost Its Focus. Keypress_event Doesnt Work
Hi

i am running a motor using my vb application. when it starts, i am displaying a dialog form. user has to press any key of the keyboard to stop this move. so, i am using key_press() event. thats in that dialog form.

but, if i open other application or window, that dialog form loses its focus and i am not able to stop it instead of pressing any key. because that dialog form lost its focus. and keypress_event() is not happening.

how could i solve this problem?
please help me.
Thanks
neel

Capturing Events Without Any Focus On A Form.
I have an application that shouldn't have any UI and thus no form focus. How can I capture events like pressed keys with it?

Set Focus To Form To Allow KeyPress Events? (VBA Excel)
i have a form with some command buttons in VBA - Excel

i want the form to be able to take KeyPress events.

if i disable the command buttons it works Ok, but that's not very helpful.

i've tried
Code:
Private Sub UserForm_Activate()
    frmATM.SetFocus
End Sub
 
and
Code:
Private Sub cmdButt2_Click()
    frmATM.SetFocus
End Sub
 

and both give Method Or Data Member Not Found.

anyone know what i'm doing wrong?

Maintain Line Of Focus After Focus Is Lost On A Listbox ?
I have two listboxes on my firm.
In the first, one selects which Report DLL to use, and then when that is selected, my app creates a new instance of that DLL and loads up all available reports into the second listbox.

So you click on the first listbox, and the blue line select thang goes across that line to show you have selected something.
Just like any other listbox does.

But then you select an item for the second listbox, and the blue line disappears from the first listbox.


So when you're looking at the screen, if you don't remember which DLL you selected, you wouldn't actually know which DLL the second box is referring to.

Ideally the first listbox should retain that blue line while at the same time the second listbox should aswell.


Any thoughts ?

Lost Focus
I have the majority of my game inside one if statement. (Its a simple game). I want it so if the game loses focus incase you click out or something popups up infront of it I want the game to stop running. All I need is a simple command hopefully a boolean so I can place it in the if statement. I've tried Me.Focus but whenever I hoverover a button in the game it pauses so I don't think thats it.

Can this be moved to the .net game section? Sorry.

Lost Focus
Hi, I face a object lost focus problem. Anyone of you know how to make text box automatic lost focus with press any key, or other method to let text box continue input a data every times without press any key. This is very urgent for me to know, I hope you can share your knowledge with me. Thanks you very much.

karencyl

Lost Focus Again
Hi,

I have 3 textboxes tabbed 0 to 2.
I have 1 button that call another form.

When i'm in third textbox and i press button i join to another form but when i close the second form my focus goes to first textbox instead of stay in third textbox. How can i prevent it.

I use textbox3.setfocus but it goes to textbox number one anyway.

Thanks.

Lost Focus
Hi,

I have a form with all my texboxes tabbed. from 0 to 5. I have a button in thrid control. When i click it i call another form to make a search. when i double click the record i'm looking for, the focus in the original form go back to the first control tabbed 0.

I need the focus in third control, but it goes to 1.

What can i do?

Thanks

On Top Without Focus Lost
i have a lil program, a chat program, but i dont need help with the chat stuff. i have a lil popup window (like that on msn, informing you of new events etc) ive set it to always on top, but when i opens it put itself on top, but takes the focus off (meaning that if your typing sumin then the keys will be sent to this window now, i was just wondering how i can make it so that the window is always on top, but isnt given focus. any ideas?

Lost Focus?
I code
Private Sub Form_LostFocus()

This Sub doesn't ever get control.

??????

I would expect when I click on anything else in windows and thus the form loses focus that I would get control here.

Mac

Lost Focus
Is there any way to know what control is gaining focus during the lost focus event of the current control?

I have two command buttons (save and cancel) that I need to exclude from the validation that happens on the lost focus of a VSflexGrid. On the lost focus of the grid, if the user has made changes they need to be asked if they want to apply or cancel those changes (in the case they do not select the command buttons to save or cancel). It's working great, except for when they select the save or cancel button, they get the message asking them if they want to save or cancel. There are many controls on the form so to go through every possible user action would not be an option. I really need to stick with the Lost Focus of the grid, but I need to know if the user selected one of the two command buttons which caused the lost focus.

Any suggestions would greatly be appreciated!!

Lost Focus
I have a rich text box and a treeview.

When I make changes to my rich text box and then leave the rich text box, I want to take action based on the currently selected node of the treeview.

Problem is, if I click a node while the rich text box has the focus, the treeview switches nodes BEFORE my rich text box loses focus.

Anyone know a work-around for that?

Thanks!

PS: the action above involves a database, so I really don't want to take the action with each change of the rich text box or I fear there'll be too much processing going on against the database.

Lost Focus
Hey guys..I've almost finished writing my code, but I need to know how to get it to work when I leave my text field: I wrote the following code:

Private Sub TextBox4_LostFocus()
If Not IsDate(TextBox4.Text) Then
MsgBox "Please input a valid time."
Else
TextBox4 = Format(TextBox4.Text, "hh:mm:ss AMPM")
End If
End Sub

but when I tab out/leave textBox4 my code does not trigger and run the time check. (It does work properly though if I apply it to a command button on click) Anyone see any problems with my code - to get it to run upon exiting a textbox field? Thanks!

Lost Focus Problem, Need Help Please
Hi everyone, I am writing a small program that will act as a voting system. The problem I am having is with the user details section. What I want to happen is if the user leaves a field without entering anything he gets a popup error and then gets put back to that field.
Here is the code I worte for that -

Code:
Private Sub txtFirstName_LostFocus()
If txtFirstName.Text = "" Then
MsgBox "Please enter a First Name", , "Error"
txtFirstName.SetFocus
End If
End Sub

If I use this on more than one text field (eg LastName) I get stuck in an endless message box loop.

Does anyone have any ideas?

Thankyou in advance

Access Lost Focus
I have a database that merges with word and prints letters. Once the printing starts, the database loses focus. (is not active window) How do I make the database active again? (or at least the db window be the active window)

Got/Lost Focus Event
Is it possible to mimic a got focus/lost focus event for a cell?

I would want to invoke a messagebox automatically when a cell receives focus, and then when it losses it.

Which Cell Has Lost Focus
Hi all,

Is there a way i can pick up which cell on a worksheet has been moved off of in the code??

Thanks,

Lost Focus Dilemma!
I have a textbox, that when I lose focus, I do some "stuff". I also have a button, that when I push it, it does some other "stuff". However, if I am in the textbox, then click the button, the textbox "stuff" gets done, but the button "stuff" does not. I know I could probably re-code some things to get it to work properly, but does anyone have any ideas on how to get this setup working? Thanks in advance!!!

Textbox (lost Focus)
Is it possible to code something when a textbox lost focus.
I need to run a calculation soon as an other textbox is in focus in the same
form. I have tested the textbox_change part, but the calculation runs for
every digits input in the textbox, I don't need to run the calculation before
the "hole" digits/figure is inputed.

Determining Who Lost Focus
Ok, I know there is an Event for each object on the form that fires when the object loses Focus. But I want to avoid using that in this case. The reason should become clear as I explain the situation.

I have a form that has 5 Text Boxes. On the Menu I have placed options for the user to click that will insert special characters (about 40 various options) into one of those lines, placed where the insertion point is located. That means I need to know who lost focus.

If I use the LostFocus events, then I need to place the code for each of the 40 options in each of the 5 LostFocus events. Rather difficult to modify down the road don't ya think?

Or....

Maybe the way to go about this is to use the LostFocus events, but instead of having the actual code for each option there, call another function passing the object that lost focus. That way all the LostFocus events are the same, and I can have 1 section of code to handle the options. Hmmm...

Assuming no one has a better idea that is.

Thanks.

About Get And Lost Focus Event
i'm using visual basic 6 and i have these simple project:

Code:
Option Explicit

Private Sub Form_GotFocus()
MsgBox "Hello"
End Sub

Private Sub Form_LostFocus()
MsgBox "Bye"
End Sub

why the LostFocus form Event is ignored?(i don't know if these is importante: i don't have any updates installed..)
thanks

Problem With VB Lost Focus
Hi Guys,

With this following code i tried to check the events usage....actually i did some coding for a text control in its lost focus event. So when a user clicks the text box first and then moves the focus to somewhere say (Save button)(cmdSave) in this case only the lost focus event is happening(i.e the code under the lost focus is executed)but not the click event of Save.I t has to execute both of the lost focus code as well as well as the next event code rite?...

actually i am facing tis problem in my application...tis is jus a sample to get the scenario for u...

Pls let me, know how to make the save event to happen....please find the sample code shown below...



Private Sub cmdSave_Click()
MsgBox "Are you sure"
End Sub




Private Sub Form_Load()

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
MsgBox hi
End If

End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
MsgBox "keyup"
End Sub

Private Sub Text1_LostFocus()


Dim KeyAscii As Integer


If Me.ActiveControl.Name = "cmdSave" And Not Chr(vbTab) = Chr$(9) Then
Call cmdSave_Click
End If



End Sub

Detect Lost Focus
Hi,

I got problem here.
I have FRAME control, on this frame got many other object (textbox, listview, etc).
This FRAME will popup when user click commandbutton on FORM1.

My question is how to close this FRAME (make it invisible)
1. When user click outside the FRAME
2. When user hit esc key, while cursor can be on one of control on the FRAME

I'm try to duplicate what standard combobox do, but adding some advanced function.

Please help guys.

How To Get The Lost Focus In SSTAB
hi all,

I have a SSTab control and i have 5 tabs in it.
i enable and make visible some controls when i click on 2nd table.

I want to make is visible false when i click on the other tab ro any other control in the form , my form background is not exposed. Its compactly covered by all controls.

so when i loose focus from 2nd tab i want to make the visibility false ( its a runtime created control, which is in 2nd tab).

my question, i dont to write code in each and evry control in the form , infact when come out of the 2nd tab it should be fired.

I tried with sstab lostfocus, it doesn't work !!!

Lost Focus And Colour Changes
I have a main form and several user controls which are fired in the main form at different events.

When the user controls get the focus the main form loses focus and the colour scheme changes. (lost focus colour scheme)

I do not mind the main form losing focus but is it possible to prevent the colour changes. In other words the user will not know whether the form has the focus or not.

Lost Focus Problem
hey,
I have 2 textbox and one listview.
When the first textbox losses focus, i want the text to be updated in the listview.
thing is that if i'm moving from textbox 1 to textbox 2, the update will be k, but if i'm inserting a text, and then moving with the mouse to the listview (clickin another item in the listview), it wont update the text in the listview, even if the lost focus event fires.
what to do?

GOT And LOST Focus Of Controls
Hi all!

Lets say I have 20 objects on the form (Textboxes, ComboBoxes, etc...). I want to change backcolor of the object when it gets focus and change it back to original when looses it.

Is any other way then just put code on GotFocus and LostFocus events for each object?

I know I could use Timer and loop throught controls collection to see which one is Active and change color, but still is any other ways to do it.

Thanx

How To Lost Focus To Print
I need to print a form. It has textboxes and there is always one of them with the cursor sign blinking. When i print the form i can see the cursor in the paper. How can I remove it to print???

Thanks!

JCI.

Lost Focus Statements
what does this codes do
Private Sub Picture1_LostFocus()
if r = 0 then s = val(screen1.text)
if y = 1 then r = z + s
if y = 2 then r = z - s
if y = 3 then r = z * s
if y = 4 then if s = 0 then MsgBox "cant divide by zero !!!" else r = z/s
Screen1.text = Str(r)
End Sub

I know what the entire middle does, but I dont know they poinrt of private sub picture1.lostfocus()
and screen1.text = Str(r)

Lost Focus Problem
I have a rich text box and a treeview.

When I make changes to my rich text box and then leave the rich text box, I want to take action based on the currently selected node of the treeview.

Problem is, if I click a node while the rich text box has the focus, the treeview switches nodes BEFORE my rich text box loses focus.

Anyone know a work-around for that?

Thanks!

PS: the action above involves a database, so I really don't want to take the action with each change of the rich text box or I fear there'll be too much processing going on against the database.

Lost Focus Event
I have an OLE container on a form. Whenever a button is clicked (on the same form), I have code in the lost focus event of the OLE container, which is fired. The problem, however, is that the click event of the control that originally caused the OLE container to lose focus, is never called.

I also attempted to use the Validate method instead of the lost focus method to perform my actions, but although the CausesValidation property of the container is set to true, it is never fired either.

Has anyone else ever heard of these particular issues with regard to OLE and lost focus/validate?

Thanks.

north.

Focus Lost With MDI Child?!
How come that when I add a windows to visio through its windows collection (with its add method)

and that I set one of my window's parent to be this newly created window, when I click in my very inner window, the focus seems to be only in that window, therefore not in visio itself ;(

that sucks!

How Do I Know That My Program Has Lost Focus
Is there anyway I can come to know that my program has lost focus. ie... if some one clicks anywhere else other than my program, or minimizes it.

I can use ZOrder to keep my program on top, but situation demands that my program should not be terminated improperly using Task Manager and it would be performance degrading if I use ZOrder every 1 milliseconds

Is there anyway I can make my code perform if a user does an End Task on my program

To Make It Not To Lost Focus?
Hello

I have trying to change richtextbox selfontname,selfontsize....etc properties.I have try to make a small program which can change these properties with combobox (combo1 for selfontsize,combo2 for selfontname) . I select a part of text in richtextbox then want to change its selfontsize or selfontname with combo,selected part of text become unselected.How can I stops it?I want to use it like word;select text and change property.How?Thanks...

Deactivate? Lost Focus?
I have a small strip of buttons that have other forms as dropdown menus.

They all have the 'Always on top' set. Is there a way to trigger an unload or something when the focus is give to another app?

I have tried Deactivate....Nope
Lost Focus....Nope

I know I could use a timer....but. I would rather not.

Any help would be great

Thanks!

C Programmer Lost Focus
The transistion for a "concieved to be" hard lanuage like C to one like Basic is harder than I thought!

I am a bit confused by where the "focus" of the program is at any given moment. In C from when I start i.e

void main(void)
{
do this
then do this
then wait here untill event X happens
}

I always know where the program is and what its doing.

One of my main questions is where does the program start from? As far as I can tell the program "starts" in the Private Sub Form_Load() of my main form.

From here I am calling my functions as if this was main(void) in C. Is this the right thing to do?

Thanks

The Lost-focus Event
hello.
on my form form i have 2 text-boxes txtA , txtB
and i have a lot of other controls.
i want to check the data that was enterd to txtA after the user finshes entering it and clicking on other control.
BUT i dont want to check it if the user click on txtB.
how can i do it?

Lost Focus Text Box
need to not allow user to focus in display text boxes by lost focus, was wondering how to code this?

Lost Focus On MDI Parent
Hi Guys,

I have an application which has a home window and that is an MDI parent. Unfortunately, I could not find a getfocus or lostfoucs event for an MDI parent.

Here is what I am looking for :

If the end-user is using my application (It is not full size of the screen), and if he CLICKS on some other application, My application goes to the status bar though the windowstate is STILL Normal. Thats fine. What I want is I want to take some action, when my application LOSTFOCUS. That means, when my MDI Parent form lost focus.

How I can tace the LOSTFOCUS event in an MDI Parent form?

Please help. Thanks.


San.

Lost Focus The Program
Does anybody know how to receive event when the program loses the focus.I want to start the timer when a user minimize my program or change the focus to another.

Hitle

Copyright © 2005-08 www.BigResource.com, All rights reserved