By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

Esc key

P: 56
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?
Jan 18 '08 #1
Share this Question
Share on Google+
4 Replies


QVeen72
Expert 100+
P: 1,445
Hi,

You have to write this code in all the forms_KeyPress event:
make All form's "KeyPreview = True"

Expand|Select|Wrap|Line Numbers
  1. If KeyAscii = 27 Then
  2.     frmMain.Show
  3.     Unload Me   ' Write this If you want to close existing form
  4. End if
  5.  
But I dont think its a Good Idea to do this..

Regards
Veena
Jan 18 '08 #2

Expert 5K+
P: 8,434
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?
Jan 21 '08 #3

P: 56
the main form is jst hidden everytime not unloaded while other forms keep literally loading and unloading as per the user inputs
Jan 21 '08 #4

Expert 5K+
P: 8,434
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...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  2.   KeyCode = 0
  3.   MainForm.Show
  4. End Sub
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.
Jan 21 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.