How to give focus to the new instance of a form?

331 Views Asked by At

I've a program in vb .net with a form named Form1. The form has button when I click on the button a dialog window appears. The dialog window has two buttons OK and Cancel. When the OK button is clicked a new instance of Form1 is created and the new instance is shown. See below code.

Private Sub ButtonOK_Click(...) Handles ButtonOK.Click  
Dim frm1 As New Form1  
frm1.Show()  
End Sub

The problem is when a new Form1 is created by the above code, the previously created Form1 gets focused and the newly created Form1 looses focus. But I want the newly created (latest) Form1 to get the focus. How do I do it?

1

There are 1 best solutions below

1
SoundWaves On

I have an application that I need to force the user to input information on a new form before proceeding. You can force the new form to show on top and give it focus by doing the following.

 Dim frm1 = New Form1()
 frm1.Show()
 frm1.WindowState = FormWindowState.Normal
 frm1.BringToFront()
 frm1.TopMost = True
 frm1.Focus()