What code in VB.net 2010 do I need to set a window to come to the front of the screen.
What I am trying to achieve is to display an urgent alert type, its a form, for certain reasons I am not using message box.
Someone suggested the following code, but this does not work:
Private Sub frmMessage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.BringToFront()
End Sub
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With