Results 1 to 15 of 15

Thread: [RESOLVED] Form in a form

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Location
    In the midst of corn, cotton, and beans
    Posts
    185

    Resolved [RESOLVED] Form in a form

    I need to have a maximized form with another form visible inside the first, it needs to be enabled, and 'on top' of the first.

    I have tried by setting visible = true, enabled = true on both forms, however the maximized form is always on top thus hiding the other.

    Is there any way to accomplish this.

    Thank You
    RT

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Form in a form

    Look into MDI forms

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form in a form

    Or using the SetParent API.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Location
    In the midst of corn, cotton, and beans
    Posts
    185

    Re: Form in a form

    Or using the SetParent API.
    How am I to do this?

  5. #5
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Form in a form

    You could make it AlwaysOnTop, but I think Hack's SetParent suggestion is the better way to go. It's nice and easy:
    Code:
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    SetParent frmChild.hWnd, frmParent.hWnd
    Be sure to manually unload the child form in the parent form's unload event. (And set it to Nothing for good measure.)

  6. #6
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Form in a form

    Is it a must to use the SetParent API? Because i try to stay away from it. I don't see why it is really needed with MDI forms could someone please explain?

    Thanks HL

  7. #7
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Form in a form

    Any particular reason you don't like the SetParent API?

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Form in a form

    Any reason to not just set the form you want on top to OnTop?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Form in a form

    No i stay away from it when dealing with MDI forms, thats all.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Location
    In the midst of corn, cotton, and beans
    Posts
    185

    Re: Form in a form

    You could make it AlwaysOnTop, but I think Hack's SetParent suggestion is the better way to go. It's nice and easy:

    Code:
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long 
    SetParent frmChild.hWnd, frmParent.hWnd
    Be sure to manually unload the child form in the parent form's unload event. (And set it to Nothing for good measure.)
    What are the variables (hWndChild, hWndNewParent) ? How do I use this function?

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form in a form

    Quote Originally Posted by Hell-Lord
    Is it a must to use the SetParent API? Because i try to stay away from it. I don't see why it is really needed with MDI forms could someone please explain?
    It isn't needed with an MDI project, but the OP's question did not mention MDI.
    Quote Originally Posted by re_turner_jr
    What are the variables (hWndChild, hWndNewParent) ? How do I use this function?
    Those aren't functions, they are parameters. The first is the handle of the window to be moved, and the second is the handle of the window it will be moved to.

  12. #12
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Form in a form

    Quote Originally Posted by re_turner_jr
    What are the variables (hWndChild, hWndNewParent) ? How do I use this function?
    They are the HWnd properties of the parent and child forms. I already gave you an example, which you quoted. Here's another:

    SetParent [name of child form].hWnd, [name of parent form].hWnd

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form in a form

    When I've used this, I always found putting form directly into another form to look a little awarkward, so I always put the second form in a Frame on the first form.

    It just looks nicer. In this case, you would use the Frame's hWnd.

  14. #14
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Form in a form

    I kinda like the form within a form results because the user can then move the child form around the parent form to wherever they want. But if you need the child form to always be in the same place, then yeah, the frame idea is probably good.

    Though I think there's a Moveable property you could set to False.

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Form in a form

    Using the MDI approach is the proper way to do what you want. Using the SetParent API also creates other display issues like if you want to display the child form in a particular position then you need more APIs to position the form. Also, it will still retain its titlebar which the user can use to close the child form but that may then create a display issue or switching child forms issues. The MDI forms take care of allot of this form you.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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