none
VB.NET 2015: Get the app on top and the winform active RRS feed

  • Question

  • Hi. Firstly thanks for your attention.
    I am working on a TCP Chat software, and needs to know if my winform PrivateConversation is active, otherwise should be play a sound. I was try with focus, active, etc, but i don get it.
    I need also to know if my application is on first plane (on the top), because if the winform of PrivateConversation is focused but my applicatio is bellow (example a excel app), i need to alert it. 
    Thank's for your time.
    Thursday, June 27, 2019 7:48 PM

All replies

  • Hi,

    Do you want a judgment like this?

      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim timer As Timer = New Timer With {.Enabled = True, .Interval = 3000}
            AddHandler timer.Tick, Sub()
                                       For Each f As Form In Application.OpenForms
                                           MsgBox("Name: " & f.Name & " Focused:" + f.Focused.ToString)
                                           MsgBox("is activted? " & (IIf(Form.ActiveForm Is f, "true", "false")))
                                       Next
                                   End Sub
    
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 28, 2019 2:50 AM
  • Hi Alex, thanks for your help. I tried it but i dont got that alertme with my form is openned, but behind of another application (Excel, Word, Winamp, etc).

    Wednesday, July 3, 2019 2:12 PM
  • HI,

    try the code:

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.TopMost = True
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 4, 2019 2:17 AM