Results 1 to 5 of 5

Thread: Form Event problem

  1. #1
    .NET Framework
    .NET 2.0
    Join Date
    Dec 2018
    Location
    Switzerland
    Posts
    2
    Reputation
    0

    Form Event problem

    I am working with an older vb dot net version.
    The program consists of a single form (no MDI application). If the user sets the cursor into another program (e.g. Word), and then back to the vb form, then at that moment I need an event to do something. I tried out several events but none of these does what it should do. Would be grateful for any help.

    LaLue

  2. #2
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Lansing, MI; USA
    Posts
    4,503
    Reputation
    1040
    Quote Originally Posted by LaLue View Post
    I am working with an older vb dot net version.
    The program consists of a single form (no MDI application). If the user sets the cursor into another program (e.g. Word), and then back to the vb form, then at that moment I need an event to do something. I tried out several events but none of these does what it should do. Would be grateful for any help.

    LaLue
    If you look in the list of events for a Form you'll notice there's a GotFocus and a LostFocus that I think you're looking for.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,224
    Reputation
    2863
    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.
    From notes of Control.GotFocus Event (System.Windows.Forms) | Microsoft Docs

    Thread moved to Windows Forms forum, always prefer a specific forum over a general one.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  4. #4
    .NET Framework
    .NET 2.0
    Join Date
    Dec 2018
    Location
    Switzerland
    Posts
    2
    Reputation
    0
    Thank you, but this occurs also when I Launch a window from my own form.

  5. #5
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,224
    Reputation
    2863
    WM_ACTIVATEAPP message - Windows applications | Microsoft Docs can tell you if another app is activated.
    Form.WndProc(Message) Method (System.Windows.Forms) | Microsoft Docs is used to receive this message.

    Example:
    Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles Me.Activated
    If anotherAppActivated Then
    'another app has been active
    anotherAppActivated = False
    End If
    End Sub

    Private anotherAppActivated As Boolean
    Private Const WM_ACTIVATEAPP = &H1C

    Protected Overrides Sub WndProc(ByRef m As Message)
    MyBase.WndProc(m)
    Select Case m.Msg
    Case WM_ACTIVATEAPP
    If Not CBool(m.WParam) Then anotherAppActivated = True
    End Select
    End Sub
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

Similar Threads

  1. Replies: 2
    Last Post: 08-03-2007, 10:47 AM
  2. Event Trigger Problem
    By wizzard in forum Windows Forms
    Replies: 2
    Last Post: 04-20-2007, 3:39 AM
  3. Form MouseDown event...
    By ALX in forum Windows Forms
    Replies: 4
    Last Post: 01-30-2007, 8:22 PM
  4. the form unload event
    By genu in forum Windows Forms
    Replies: 6
    Last Post: 06-10-2005, 12:47 AM
  5. Calling an Event from Another Form...?
    By pad in forum VB.NET General Discussion
    Replies: 1
    Last Post: 02-01-2005, 2:01 AM

Bookmarks

Posting Permissions

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