Results 1 to 4 of 4

Thread: Application LostFocus

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    35

    Application LostFocus

    Hi

    I'm creating a small utility which will run out of the notify bar. If the user clicks the notify icon it displays a form in the bottom right hand corner - this works perfectly. However I would like to listen for if the user clicks on another program (say Excel), the program will detect its lost focus and will minimise the form.

    I've tried form_LostFocus but that doesnt seem to work

    Any thoughts please?

    Thanks
    Jay

  2. #2
    Lively Member
    Join Date
    Apr 2008
    Posts
    92

    Re: Application LostFocus

    Let's see if I understand you correctly:

    When the form is opened in the bottom right hand corner, it has focus? When the user moves away from that form, say to another application, you want to minimize that form so it's not hanging open?

    If this is in fact what you mean, then you don't have to look for your application losing focus, but rather, just that form. Let's assume it's called "Form1". You want the Lost Focus Event.
    Code:
    Private Sub Form1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
            'Do your minmize here
        End Sub

  3. #3
    Junior Member
    Join Date
    Apr 2008
    Location
    Karachi, Sindh, Pakistan
    Posts
    23

    Re: Application LostFocus

    It is working on my side. I have used the following code

    Code:
    Private Sub Form1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
        Me.WindowState = FormWindowState.Minimized
    End Sub
    When Focus is removed from Form1 it gets minimized automatically.

    Also you can try the DeActivate Event

    Code:
    Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
        Me.WindowState = FormWindowState.Minimized
    End Sub

  4. #4
    New Member
    Join Date
    Jul 2008
    Posts
    1

    Re: Application LostFocus

    Don't use LostFocus. See what happens if you do this:
    Code:
    Me.textbox1.Focus() ' textbox1 placed on Form1
    Better use the Deactivate event handler.

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