First make sure to set child forms KeyPreview property to TRUE. This will ensure that your Esc key event will be captured by the form.
In the MDI form write something like:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim oFrm As *child_form_name, for exmple Form2*
If KeyCode = vbKeyFx (where x is a numer from 1 to 12) then
Set oFrm = New Form2 '...(actualy *child_form_name*)...
'...If you unload the form from within it self then you don't need this line, but if you just Hide it then you must:
'...Finaly release the object...
The Escape key press code stated above is correct except that it is general better idea to unload the form in the calling process.
You can also use vbKeyEscape constant instead of 27.
I want to know the code for the functions keys as a command for my program (Student Details)..F1 as Add, F2 as Edit, F3 as Save, F4 as Cancel, Del for Delete and Esc as Exit..and a code for running my program on other PC.
Thanks a lot!! :)
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...