Results 1 to 37 of 37

Thread: Closing the MDI CHILD Form by pressing CTRL+F4 Keys

  1. #1

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280

    Closing the MDI CHILD Form by pressing CTRL+F4 Keys

    Hi all,

    I want to Close AMD CHILD Form by pressing CTRL+F4 keys. Any idea how to do that. I've used Form_KeyPress event but its not working bcoz i have different controls on my form and those controls grabs the focus, so Form_KeyPress never executes...
    A man with nothing to live for has everything to fight for...

  2. #2
    Hyperactive Member VB IT's Avatar
    Join Date
    Feb 2003
    Posts
    381

    Get IT

    Set CHILD's Form KeyPreview = True
    And Then Add the following Code In Child's Forms KeyDown Event
    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2. If KeyCode = 115 And Shift = 2 Then Unload Me
    3. End Sub
    Sorry for Bad English.

  3. #3
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Make sure it is an MDI child.
    Set its keypreview property to true, and it should work wihtout any coding.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  4. #4

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    not working...
    i've set its keypreview property to true. Still....
    A man with nothing to live for has everything to fight for...

  5. #5
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    I opened a new project , added a MDI form.
    Changed form1 to MDI child , Keypreview = true
    Added form2, set to MDI child; Keypreview = true

    They are closing when they are active and Ctrl + F4 is pressed.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  6. #6

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    Thanks SWATTY for replying,

    i did the same thing, on one proj. the forms are Closing but on another ther are not...
    A man with nothing to live for has everything to fight for...

  7. #7
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    So you got a proj where it does work.

    Check the properties for the MDI form in both .

    As well for the MDI Child forms.

    There should be something different.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  8. #8

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    i've checked the properties,

    i m able to close/Unload the form when i press F4 but not CTRL+F4 thr. coding..

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then Unload Me
    End Sub
    A man with nothing to live for has everything to fight for...

  9. #9
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    You have to check the value of Shift in there , it should be 2 for the Ctrl key
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  10. #10
    Hyperactive Member VB IT's Avatar
    Join Date
    Feb 2003
    Posts
    381

    Chage your Code

    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2. If KeyCode = vbKeyF4 And Shift = 2 Then Unload Me
    3. End Sub
    Sorry for Bad English.

  11. #11
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Re: Closing the MDI CHILD Form by pressing CTRL+F4 Keys

    Originally posted by aks_1610
    Hi all,

    I want to Close AMD CHILD Form by pressing CTRL+F4 keys. Any idea how to do that. I've used Form_KeyPress event but its not working bcoz i have different controls on my form and those controls grabs the focus, so Form_KeyPress never executes...
    I do not know what you are talking about pal, but you do not have to code for that. Pressing Ctrl + F4 automatically closes the active MDI child form.

  12. #12

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    i have done every thing. Removed the code but it did not Unload.

    At last i tried unloading the form thr. coding that did work but CTRL+F4 is not working even if i use this code.

    VB Code:
    1. 'Closing the form if user presses F4 Key
    2. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    3.     If KeyCode = vbKeyF4 And Shift = 2 Then Unload Me
    4. End Sub
    A man with nothing to live for has everything to fight for...

  13. #13
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    check the events on the form.

    There isn't any code in the unload event which prevents it from unloading ??

    Check Form_QueryUnload also.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  14. #14
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by aks_1610
    i have done every thing. Removed the code but it did not Unload.

    At last i tried unloading the form thr. coding that did work but CTRL+F4 is not working even if i use this code.

    VB Code:
    1. 'Closing the form if user presses F4 Key
    2. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    3.     If KeyCode = vbKeyF4 And Shift = 2 Then Unload Me
    4. End Sub
    What are you guys doing ????

    You do not need no code for this. Just open MDI open some child form and press Ctrl + F4, it will close the child form. It closes on my machine. I am running win 2K.

  15. #15

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    hi swatty,
    there is no Form_QueryUnload event on my form.

    techyspecy:

    i m also confused why the hell it is not working. i m also running win 2k .
    A man with nothing to live for has everything to fight for...

  16. #16
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by aks_1610
    hi swatty,
    there is no Form_QueryUnload event on my form.

    techyspecy:

    i m also confused why the hell it is not working. i m also running win 2k .
    Post your project if you want us to help you.

  17. #17
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Originally posted by aks_1610
    hi swatty,
    there is no Form_QueryUnload event on my form.

    techyspecy:

    i m also confused why the hell it is not working. i m also running win 2k .

    I think you must have something different then we got in mind.

    Can you load the project up, so we could look into it.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  18. #18

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    Please see the attached file:
    Attached Files Attached Files
    A man with nothing to live for has everything to fight for...

  19. #19
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by aks_1610
    Please see the attached file:
    Got the problem !
    Its not closing the form because you have set its borderstyle property to 0-None. You cannot close forms with Ctrl + F4 if there's borderstyle is 0. Change it to 1 or 2 and it will close the form on Ctrl + F4.

  20. #20
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    BTW - Very colourful application.

  21. #21

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    Thanks techyspecy,

    its the client's requirement.(Can' help it). I can't change it to 1 or 2. Is there any other method to do it.

    Thanks again for the reply....
    A man with nothing to live for has everything to fight for...

  22. #22
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    I've thrown following code in the code pane of frmMain and it unloaded.

    Don't know why it won't work on your side of the screen.
    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.    If KeyCode = 115 Then
    3.       If Shift = 2 Then
    4.          Unload Me
    5.       End If
    6.    End If
    7. End Sub
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  23. #23
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Originally posted by aks_1610
    hi swatty,
    there is no Form_QueryUnload event on my form.

    techyspecy:

    i m also confused why the hell it is not working. i m also running win 2k .
    In the project u provided i did find a QueryUnload event in frmMain ?
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  24. #24

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    where is it swatty.

    i m not getting which QueryUnload event u r taking about.
    A man with nothing to live for has everything to fight for...

  25. #25
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Don't bother the QueryUnload event , it isn't relevant in your code.


    The KeyDown event did work over here.
    Attached Files Attached Files
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  26. #26

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    hi swatty,

    it worked there bcoz Command Buttons at the top are disabled. Try enabling all those Command Buttons..

    Thanks for the reply...
    A man with nothing to live for has everything to fight for...

  27. #27
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    For some reason when a button has the focus the combination of two keystrokes isn't coming through.

    I've changed it if F4 is pressed it unloads , it works.

    Depends if it is necesary the combination is used.
    If so you should set the focus on the grid after a button is clicked to let it work properly.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  28. #28
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    What are you two nutty kids doing with this easy thing. Why do you not put a command button on the form, set its cancel property to true and hide it behind any other control. Do it on every form. On this command_click event unload me. That way user can just press ESC and unload the form.

  29. #29

    Thread Starter
    Hyperactive Member aks_1610's Avatar
    Join Date
    Sep 2002
    Location
    Pune, India
    Posts
    280
    thanks swatty,

    after setting the focus on the Grid i m able to unload the form.

    sometimes such little things do matters a lot...

    anyways thanks ....
    A man with nothing to live for has everything to fight for...

  30. #30
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199

    Re: Closing the MDI CHILD Form by pressing CTRL+F4 Keys

    Originally posted by aks_1610
    Hi all,

    I want to Close AMD CHILD Form by pressing CTRL+F4 keys. Any idea how to do that. I've used Form_KeyPress event but its not working bcoz i have different controls on my form and those controls grabs the focus, so Form_KeyPress never executes...
    MDI form doesn'r respond to any key event and since your child form is borderless you'd need to use a Timer (on the MDI form, Interval = 100) and some Windows API:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    4.  
    5. Private Const VK_CONTROL = &H11
    6. Private Const VK_F4 = &H73
    7.  
    8. Private Sub Timer1_Timer()
    9.  
    10.     GetAsyncKeyState(VK_F4) Then
    11.         If GetAsyncKeyState(VK_CONTROL) Then
    12.             Unload Form1 'assuming that Form1 is that child you need to unload
    13.         End If
    14.     End If
    15.  
    16. End Sub
    Note: in order for this sample to work your borderless form will have to be the topmost at the moment.
    McGenius

  31. #31
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Originally posted by techyspecy
    What are you two nutty kids doing with this easy thing. Why do you not put a command button on the form, set its cancel property to true and hide it behind any other control. Do it on every form. On this command_click event unload me. That way user can just press ESC and unload the form.
    Are you always this cocky?
    McGenius

  32. #32
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by McGenius
    Are you always this cocky?
    I am not cocky, i'm a fun guy. I do not mind cracking jokes/sarcasm on others and always open for someone cracking joke/sarcasm on me.

    Anyway forget about me, was just looking at your previous post, how can you even suggest such a pathetic and lousy solution .. , i'm still wondering about it. *burnt*

  33. #33
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    And it's "a pathetic and lousy" because ... Do you mind to provide more argumented reply or otherwise don't bother. I belive I've mentioned that to you once before.
    McGenius

  34. #34
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by McGenius
    And it's "a pathetic and lousy" because ... Do you mind to provide more argumented reply or otherwise don't bother. I belive I've mentioned that to you once before.

    because for the sake of one damn key, you're gonna make him put a timer on the MDI which is gonna fire every 100 milliseconds for no good reason .... ( system resources after all are expensive, specially on users machines )

    BTW - you never mentioned that before - I'll note it down somewhere now .. hmm .. * looking for notepad *

    Yours - McMoronic Techy ....

  35. #35
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Yep, that's what I thought you'd say. Let me guess techy: you must be 15-16, may be 18 yo - at least your brain isn't any older. I have no intension to discuss anything with you any farther what-so-ever.
    Also, go find that Notepad and make a note: learn some manners - you'll need'm time to time.
    McGenius

  36. #36
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by McGenius
    Yep, that's what I thought you'd say. Let me guess techy: you must be 15-16, may be 18 yo - at least your brain isn't any older. I have no intension to discuss anything with you any farther what-so-ever.
    Also, go find that Notepad and make a note: learn some manners - you'll need'm time to time.
    Is this Argumentative ????? Looking at this .. you need manners more than i do ..
    Make a note for yourself:

    Only say what you mean, and always do what you say.

    Yours ... McMoronic Techy ....

  37. #37
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    I think you are ticked off with my signature. Is that bothering you .... if yes, i'll never remove it.

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