-
April 20th, 2011, 03:21 PM
#1
Esc Key Event on VB 6 Form
I have a form with a frame. i want to close form with Esc Key and i m doing this. But when frame is visible then it should hide frame but its closing form. Is there any way to hide frame when frame is visible with Esc Key and close form when frame is hidden.
i am using this.
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
If frm1.Visible = True Then
frm1.Visible = False
Else
Unload Me
End If
End If
End Sub
Any other ways to do this.?
-
April 20th, 2011, 03:51 PM
#2
Re: Esc Key Event on VB 6 Form
I tried this with a blank form and a single frame called frm1.
Your code worked perfectly.
When I ran the code, the first time I pressed the esc key the frame was hidden, then the next time the esc key was pressed the form closed.
Is there something I am missing?
-
April 21st, 2011, 12:09 AM
#3
Re: Esc Key Event on VB 6 Form
Make sure keypreview is turned on otherwise (depending on what has focus) the event may not fire when the ESC key is pressed. Keypreview will allow the event to fire regaurdless if a text box may have the focus or some other control on the form.
Always use [code][/code] tags when posting code.
-
April 21st, 2011, 01:10 AM
#4
Re: Esc Key Event on VB 6 Form
Tried it with a textbox having the focus as well, and I also have not had any issues?
Is there perhaps a timer or something doing some stuff as well?
-
July 20th, 2012, 12:28 AM
#5
Re: Esc Key Event on VB 6 Form
Try this code. Let say you have form1 and form2. You are currently oppened form2 and want to move back to form1 by pressing Esc key. For this use this key
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
form1.show
frm2.hide
End Sub
Hope i ve clear ur doub.
Thanks
-
July 20th, 2012, 01:05 AM
#6
Re: Esc Key Event on VB 6 Form
Originally Posted by yongstars
Try this code. Let say you have form1 and form2. You are currently oppened form2 and want to move back to form1 by pressing Esc key. For this use this key
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
form1.show
frm2.hide
End Sub
Hope i ve clear ur doub.
Thanks
I think this problem has been solved, because this thread is over a YEAR OLD. Please do not revive old threads. It messes up forum flow, and there are numerous current threads that need input.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|