dhathsato
asked on
Windows Form Focus
I have a MDI Parent with child windows included. When more than one child window is opened the user can click between these windows. When a user clicks on the window I need it to get focus and change a label value that is on the MDI Parent. Any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Create an MDI called 'MDIForm' which opens 2 forms using withevents, Add a panel and a label in the panel.
With the following code:
Public Class MDIForm
Private WithEvents form2 As New Form2
Private WithEvents form3 As New Form3
Private Sub MDIForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
form2.MdiParent = Me
form2.Show()
form3.MdiParent = Me
form3.Show()
End Sub
Private Sub HasFocus(ByVal FormName As String) Handles form2.HasFocus, form3.HasFocus
Label1.Text = FormName
End Sub
End Class
Add 2 more forms with default names and add the following code to both (mind the form name)
Public Class Form2
Public Event HasFocus(ByVal FormName As String)
Private Sub Form2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
RaiseEvent HasFocus(Me.Text)
End Sub
End Class