Focusing problem on windows form

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I have a question about the focusing on windows form control. First of all,
I have a main windows form (MainFrm) for my application, another form
(NewFrm) will be displayed if pressing one of the button on the MainFrm. I
used the NewFrm.Show() method to open the form. However, if I switch the
focus to another applcation (eg. Outlook, IE etc) and then switch back to my
application program. I lost the focus on NewFrm and MainFrm display on top
instead occasionally. I need to use the function key ctrl + tab in order to
get back the focus on NewFrm.

All I want to know is there any method can let my application program always
focus on NewFrm after switching back the focus from other application in
task bar?
 
You could try something like this:

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Activated

Dim AForm As Form

For Each AForm In Application.OpenForms
If AForm.GetType Is Form2.GetType Then
AForm.Focus()
Return
End If

Next
End Sub
 
Back
Top