VB.net Bring Window to Front
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Now, take the name of the window you want to bring to the front, and do the following:
string name = "Untitled - Notepad";
IntPtr ptr = FindWindow(null, name);
SetForegroundWindow(ptr);
This will bring the window to the front of the screen.
It should be enough that you set property TopMost
of the window that you need to get on the top of the others.
Form.TopMost = True
Try using the .Shown event. Here is the code for a three form test. At the end of the button click event, Form3 should be on top of Form2, on top of Form1.
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Me.SendToBack()
Dim f2 As New Form2
f2.Show()
Dim f3 As New Form3
f3.Show()
End Sub
End Class
Public Class Form2
Private Sub Form2_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
Me.BringToFront()
End Sub
End Class
Public Class Form3
Private Sub Form3_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
Me.BringToFront()
End Sub
End Class
try
me.Activate()
This outta do the trick
EDIT: I googled to find backup for my answer
My Case
EDIT2:
There seems to be a few things that work. the Above as well as
''depending on setup
Me.Show
Form2.Show()
also
Form2.ShowDialog()
also
Form2.Visible = True