Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2004, 04:40 PM
Registered User
 
Join Date: Mar 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I get a form to close w/esc key (VB 6.0)

How can I get a form to close when I press the ESC key on the keyboard in Visual Basic 6.0?

Thanks!

 
Old March 23rd, 2004, 04:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. do something like this..

Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then
        unload me
    end if
End Sub


HTH

Gonzalo
 
Old March 23rd, 2004, 04:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would add be sure to set the KeyPreview property of the form to True.

Larry Asher
 
Old March 23rd, 2004, 08:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If your form has a Cancel button, set its Cancel property to True. I suggested to use a Cancel button because in this way the user does not have to know to hit Escape to dismiss the dialog.

Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
Close all MdiChield form from open one form/Button salman .NET Framework 2.0 6 December 10th, 2007 03:21 AM
Close all MdiChield form from open one form salman .NET Framework 1.x 0 November 8th, 2007 12:32 AM
ESC button as Access Key NEO1976 C# 2005 1 January 18th, 2007 02:38 PM
how to disable a close button on VB form chanti VB How-To 2 September 30th, 2004 06:21 AM
multiple projects within the solution(close Key) rosalynb VS.NET 2002/2003 1 September 28th, 2004 12:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.