Results 1 to 3 of 3

Thread: How can I display a form within a form?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381

    How can I display a form within a form?

    Can someone show me how to display a form within a form.

    I do not wish to use a MDI interface for my current project but would like my main form to be always open and displayed with selected forms opened and embedded in my main form.

    The main form has an outlook style listbar on the left side of the form. What I want to do is display the form selected by the user from the listbar to the right of the listbar. I don't want it to merely be on top of the main form but to be displayed in it, similar to a subform but without the scroll bars.

    I saw a tip on VB Tips and Tricks about this but never have been able to get it to works. I downloaded a free subform ocx from somewhere a wile back and it worked great for what I want but since it is designed as a subform controls it assumes you always want scroll bars but I don't. My forms will be sized to the area to the right of the listbar. The main form will not be resized.

    Any help here would be greatly appreciated.

    Thanks, Rev. Michael L. Burns

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Hi Michael, try the code posted below, and see if that is what u'r after.

    VB Code:
    1. 'Sample, start a new project, add two forms then add this code to them
    2. 'in Form1 add this code
    3. Option Explicit
    4.  
    5. Private Sub Form_Load()
    6.     Load Form2
    7.     Form2.Show
    8. End Sub
    9.  
    10. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    11.     Dim f As Form
    12.     For Each f In Forms
    13.         Unload f
    14.         Set f = Nothing
    15.     Next f
    16. End Sub
    17.  
    18.  
    19.  
    20. 'in Form2 add this code
    21. Option Explicit
    22. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    23.  
    24. Private Sub Form_Load()
    25.     Dim l As Long
    26.     l = SetParent(Me.hWnd, Form1.hWnd)
    27. End Sub
    -= a peet post =-

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381
    Peet,

    Thanks for the quick reply. That would do but I wanted to embed the second form inside the first.

    I just found and example project that seems to do what I want. I have attached it for you so that you can see what I was looking for.

    Thanks again for your quick reply.

    Michael
    Attached Files Attached Files

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