Gopal Gopal - 11 days ago 4x 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


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