LostFocus/Leave event

shawne

Well-known member
Joined
Feb 22, 2006
Messages
103
Location
Pennsylvania
Programming Experience
10+
I'm certain somewhere in here there is a thread which talks about my question, however I could spend all day looking for it. My question is:

I have a double click event on a listview that pops up another form which contains a few buttons (actions) you can take on the item you double clicked. The popup form is suppose to close once a selection is made or you navigate away from the form (IE click on the parent) ... I thought that the LostFocus or Leave event would fire whenever I click on another form or running application, but it's not, so my popup menu just sits there until you either make a selection or X out of it. What am I doing wrong?
 
Deactivate Occurs when the form loses focus and is no longer the active form.
 
What you did wrong was not read the documentation first. From the help topic for the LostFocus event:
The GotFocus and LostFocus events are low-level focus events that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the GotFocus and LostFocus events are only used when updating UICues or when writing custom controls. Instead the Enter and Leave events should be used for all controls except the Form class, which uses the Activated and Deactivate events. For more information about the GotFocus and LostFocus events, see the WM_SETFOCUS and WM_KILLFOCUS topics in the "Keyboard Input Reference" section of the Platform SDK Documentation in the MSDN library at http://msdn.microsoft.com/library.
From the help topic for the Leave event:
The Enter and Leave events are suppressed by the Form class. The equivalent events in the Form class are the Activated and Deactivate events. The Enter and Leave events are hierarchical and will cascade up and down the parent chain until the appropriate control is reached. For example, assume you have a Form with two GroupBox controls, and each GroupBox control has one TextBox control. When the caret is moved from one TextBox to the other, the Leave event is raised for the TextBox and GroupBox, and the Enter event is raised for the other GroupBox and TextBox.
MSDN has virtually everything you need and should always be your first port of call. If you can't find the required informartion or you don't understand what you do find, then it's time to look further afield.
 
For an individual just starting .NET, there is nothing WRONG with calling on the expierence of people who have much more expierence then I. The truth is you could point someone to MSDN for ALL issues which would make this forum obsolete .... What is the point of having it all if you're going to do is tell people to go look it up on MSDN. I knew that it was a simple answer that was taking me to long to find and I knew that someone on here would have it in short order. WHY OH WHY!! should I spend time digging through MSDN for an answer when I can post a question on a forum and most likely have an expierenced veteran show me the path.

If this is YOUR view of how questions should be handled, perhaps you should either redirect the web-site to MSDN or just post there link in any of your responses AS your response.....

ON TOP of that, I already had the solution, WHY INFURIATE me with a reprimand or a tsk tsk ... you should of done this instead of using the forum.......why are you here then if you don't want to answer questions....Anything can be answered by digging for it, I just chose to call on the expierence of others in a more direct manor.
 
Last edited by a moderator:
Forums are a great place to have questions answered for which you cannot find the answer. Not looking for the answer first is, in my opinion, being lazy. Why do anything if you can have someone else do it for you? If you are trying to use something in code, e.g. the LostFocus or Leave event, and it's not working then the first thing you should do is look up the documentation for that thing. Had you done that you'd have had your answer in seconds. Now that you know that, you can do so in future and you'll quite possibly have your answer in seconds instead of having to wait for someone to reply to a thread on a forum. Like I said, MSDN should be everyone's first port of call. It's where I got the vast majority of the information I needed when I taught myself to code in VB.NET and C#. MSDN will not always you provide the information you need though, so that's when it's time to look further afield, as I said previously. You can post any question you like on a forum, obviously, but whether you should is another matter. A good developer has good problem solving skills. You won't develop those with the attitude that you don't need to do something for yourself if someone else can do it for you.
 
Because I did not post that I DID search MSDN and Google for an answer to my question does NOT mean I didn't. MSDN and Google have been my backbone for learning VB since I started with scripting. I have ALWAYS made the effort to do things for myself over relying on someone else and if I do use someone elses snippet, I make it a point to understand what i'm using, otherwise it's pointless.

You assume way to much. If you are going point out what someone did wrong, make sure you have all the facts, and don't be so bold as to just come out say it unless you've got a "holyer then thow" attitude, are just looking to invoke a negative response OR it is absolutely warranted. Starting out with:

What you did wrong was not read the documentation first.
is a sure way to do such a thing. Thats just not a good line to start out with. And then calling me lazy!? Granted, that was in defense, but thats a real throw down for me. You don't know me and you don't know what i've done. How is it you can call me lazy?

I'm done with this thread, respond if you want but it's off subject now and I had my answer prior to your initial post. However, PLEASE in your future posts put more thought to your words before you respond. There are more subtle ways of calling someone wrong and lazy without coming right out and saying it.
 
Shawn, this particular request was easy to find answer to, there is no need to search MSDN for likes of this, if you have problem with Form class events you just click into the framework reference either local or online, go directly to Form class, browse its Events list and read the descriptions (this was where I copy/pasted my answer from), if you're uncertain about a particular event just click into the topic to get further info. Here is the Form class events list http://msdn2.microsoft.com/en-us/library/td1s43eb.aspx Looking at the tree at the left pane you see it is well organized for
VB.NET:
-Namespace
  -Class
    -Members (lists all)
    -Constructor
    -Methods
    -Properties
    -Events
 
Back
Top