Results 1 to 4 of 4

Thread: unloading a hiden form

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    37
    I made a game with a 'Hide' button. This hides the game. I'd like the user to be able to press a certain key to either exit or make the game visible again.

    Any ideas on how to do this?

    Thanks

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    What do you mean by Hide? Is it a picturebox on which your game is on that you hide, or do you minimze it or do you just make the window invisible?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    hmmm try this:
    Code:
    'When the user presses V it either hides or show the form.
    'When pressing C it closes the form
    'Place another form in your project (Form2)
    
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyV Then
    Form2.Visible = Not Form2.Visible
    End If
    If KeyCode = vbKeyC Then Unload Form2
    End Sub
    
    Private Sub Form_Load()
    KeyPreview = True
    Form2.Show , Me
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    Dim frm As Form
    
    For Each frm In Forms
    Unload frm
    Set frm = Nothing
    Next
    End
    End Sub
    Hope that helped a bit!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4
    Guest
    If the Form doesn't have focus then use GetAsyncKeyState API.

    Add the following to a Form with a Timer
    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
    
    Sub UnloadForms
        Dim frm As Form
        For Each frm In Forms
            Unload frm
            Set frm = Nothing
        Next frm
    End Sub
    
    Private Sub Timer1_Timer()
        'Show Form1 if C is pressed
        If GetAsyncKeyState(vbKeyC) Then Form1.Show
    
        'Unload if Q is pressed
        If GetAsyncKeyState(vbKeyQ) Then UnloadForms
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width