I am doing a project in VB6 where i have a main form and several other forms the user can go to thru the main form. i want that at any point of time in those forms when the user presses the esc key, the main form should be loaded. how do i do that?
Esc key
Collapse
X
-
Hi,
You have to write this code in all the forms_KeyPress event:
make All form's "KeyPreview = True"
[code=vb]
If KeyAscii = 27 Then
frmMain.Show
Unload Me ' Write this If you want to close existing form
End if
[/code]
But I dont think its a Good Idea to do this..
Regards
Veena -
Again, I think we need a bit more background. For instance, when you say "loaded" do you mean it literally, or is that just a generic expression meaning you want it on the screen?
Are you unloading the main form at any point, or just hiding it? Do you want the "sub form" to go away?Comment
-
Hm. Sounds as though the simplest thing, then, would be something like setting KeyPreview property to True on each of the other forms, and include something like this on each form...
[CODE=vb]Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
KeyCode = 0
MainForm.Show
End Sub[/CODE]
Not knowing the exact situation, I don't know what else you need to do at that point. This might include stopping the user if they're in the middle of something, hiding or unloading the current form, or whatever.Comment
Comment