Esc key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mclueless
    New Member
    • Jan 2008
    • 56

    Esc key

    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?
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    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

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      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

      • mclueless
        New Member
        • Jan 2008
        • 56

        #4
        the main form is jst hidden everytime not unloaded while other forms keep literally loading and unloading as per the user inputs

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          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

          Working...