Results 1 to 11 of 11

Thread: [RESOLVED] Window clicked away from

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    402

    Resolved [RESOLVED] Window clicked away from

    Currently I have an application that runs ok, however as it does not fill all the screen (intentionality) and it is possible to click another part of the screen / form of a totally different programme.

    What I need to do is test if this is the case when a function is triggered.

    I have tried me.focused, but the value of this never changes

    Is there a form.???? Control that I can test ?

    Thanks in advance

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Window clicked away from

    Given that you can simply use the Help menu to open the documentation and then read the list of events the Form has has, why do you need to ask us that question? It would take you less than five minutes to read the name and description of every Form event.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    402

    Re: Window clicked away from

    Because I have looked and can't find the list of events. Suggesting the appropriate answer would have been a lot quicker I.E two words (form.????) than writing 3 lines that don't really help some one who can't find the answer.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Window clicked away from

    Yeah, looking at the list of events you would thing that Me.LostFocus would be the event you want, but it never fires.
    If you read through the LostFocus event on msdn, in a small section near the end in a Note they let you know...
    "...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...."

    So, to answer your question, add code to the Form's Deactivate event handler to know when your form has been deactivated by clicking outside the form (or shift-tabbing away, etc...)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    402

    Re: Window clicked away from

    passel, that's really helpful. I can understand it and indeed written an example which shows that it works. For reference (for others reading this) the events are

    Code:
        Private Sub Form1_Deactivate(sender As Object, e As EventArgs) Handles Me.Deactivate

    Code:
        Private Sub Form1_Activate(sender As Object, e As EventArgs) Handles Me.Activated
    I assume I could have been looking for a long time for form.??? that i could test.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Window clicked away from

    Quote Originally Posted by Signalman View Post
    Because I have looked and can't find the list of events. Suggesting the appropriate answer would have been a lot quicker I.E two words (form.????) than writing 3 lines that don't really help some one who can't find the answer.
    I don't understand how people who aspire to write software seem unable to use it themselves. You're not the only one but, to be frank, if you couldn't find the list of events then you really haven't looked. Even disregarding the local Help documentation, which is two clicks away in VS, I just searched at the MSDN web site for "form events" and the documentation page containing the list of events for the Form class was the first result:

    https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

    I also just Googled "vb.net form events" and that same page was the second result. If you really had looked then you'd have found it.

  7. #7
    New Member
    Join Date
    Sep 2015
    Posts
    13

    Re: [RESOLVED] Window clicked away from

    Lol makes since he makes a program but really dont know how to work vb.net intentionality

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    402

    Re: [RESOLVED] Window clicked away from

    Perhaps it is because the less experienced of us were trying to achive something in a way that is not possible, as such we are looking for the wrong thing. As I need to know in the code if a different form has been selected, I was looking to test form1.??? (I did not need to trigger an event, simply test for it some time layer). It would appear that this does not exist and I need to create a event handler. Which is what I have done. In the event handler it simply sets a flag true or false. This flag is then Used in the code.

    If you look for the wrong thing you are not going to find the answer. As an aside, I have always found Ms help, not overly helpful if you don't know exactly what you want.

  9. #9
    New Member
    Join Date
    Sep 2015
    Posts
    13

    Re: [RESOLVED] Window clicked away from

    Lol first you said you dont need to trigger a event, now you are saying that you needed to create an event handler which is almost the same exact thing your doing it. Vb.net isnt hard and has alot of work arounds.

  10. #10
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: [RESOLVED] Window clicked away from

    Quote Originally Posted by ReallyBasic View Post
    Lol first you said you dont need to trigger a event, now you are saying that you needed to create an event handler which is almost the same exact thing your doing it. Vb.net isnt hard and has alot of work arounds.
    Signalman's desire was to find a property of the form that he could check to see if it was the active form or not.
    He didn't need an event handler if he could query the form to see if it was active.
    He ended up writing the event handler and setting the "property" himself, to be referenced later.

    Depending on where the code is running, you may have been able to use the ActiveForm to test for what you wanted.
    e.g. if the code is in your main form and you're testing to see if your main form is currently active
    Code:
    If ActiveForm is Me Then
      'My form is active
    End If
    If your main form is Form1, and you have code running in another form, then
    Code:
    If ActiveForm is Form1 Then
      'Form1 is active
    End If
    I don't know where your code runs, but checking the ActiveForm may be another option more aligned with what you were attempting to do, (which I didn't fully comprehend when first reading your first post).

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: [RESOLVED] Window clicked away from

    Quote Originally Posted by Signalman View Post
    Perhaps it is because the less experienced of us were trying to achive something in a way that is not possible, as such we are looking for the wrong thing. As I need to know in the code if a different form has been selected, I was looking to test form1.??? (I did not need to trigger an event, simply test for it some time layer). It would appear that this does not exist and I need to create a event handler. Which is what I have done. In the event handler it simply sets a flag true or false. This flag is then Used in the code.
    That could be an explanation for why you had to ask the question in the first place but, even then, if you haven't read the documentation for the class you're using and checked the entire member list then you really shouldn't be asking the question because you haven't really made a proper effort. If you have done that and still not found what you need, then you should think about posting a question. It also doesn't explain why, when I specifically mentioned the event list for the Form class in the documentation, you said that you couldn't find it when you're now saying that you didn't know to look for it.
    Quote Originally Posted by Signalman View Post
    If you look for the wrong thing you are not going to find the answer. As an aside, I have always found Ms help, not overly helpful if you don't know exactly what you want.
    That doesn't really cut it I'm afraid. I was a beginner once too and I always checked the documentation first. The more I used it, the more useful I found it as I got used to how it worked. The fact that you might not find what you want is no reason not to look. Even when I was relatively inexperienced myself, I was able to answer questions on this very forum on subjects that I had no prior experience with simply by reading the appropriate documentation. I'm no genius. If I can do it, I know that others can too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width