• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 527
  • Last Modified:

vb.net bring to front

I have a little app that shows me an alert.
I would like to know how can I bring that window to the front. for example when im working on a different program or browsing the internet I need it to bring the app to the top of all other opened apps..
1 Solution
käµfm³d 👽Commented:
Have you tried using the BringToFront method? If that does not work, then you might try setting the TopMost property to True. Finally, and likely, if neither of those work, then you will need the SetForegroundWindow Win API method. Here is an example of the latter:

Imports System.Runtime.InteropServices

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Timer1.Interval = 2000
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    End Sub
End Class

Public Module WinAPI
    <DllImport("User32.dll")> _
    Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
End Module

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now