Gopal Gopal - 1 year ago 83 Question

How to close the child form

Using MDI and Child Forms



Me.MdiParent = MDIMain


Private Sub form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
End If
End Sub

The above code is working for MDI Form (form name is mdiform1), but not working for child form1, when I press the escape key, it is closing the MDI Form instead of Child form.

I check the Child Form Name also, name is form1 only.

What was the problem, i need to change any property of child form.

Need code help

Answer Source

This works for me

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Escape Then
            For Each child As Form In Me.MdiParent.MdiChildren
            Next child
        End If
    End Sub
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download