CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 1999
    Posts
    15

    Inserting a Form into Another form

    Hi All:

    I would like to insert one form into another form. Is this possible? Lets say I have a master form named frmMain and three other forms with names form1, form2 and form3. The master form has some form selection menus to select which form to load. Is it possible for me to load/unload the forms in the master form (frmMain)? I have attempted using the OLE object control in frmMain. However, only the icon and name of the other forms are displayed in the OLE control (in frmMain).

    I have never seen any articles on this issue.

    Sincerely,
    Hansel
    [email protected]


  2. #2
    Guest

    Re: Inserting a Form into Another form

    What about using MDI?
    Vlad


  3. #3
    Join Date
    Dec 1999
    Posts
    15

    Re: Inserting a Form into Another form

    I've thought of using MDI. However, I don't get the effect I want. Form instance, I have frmMain as having controls embedded within and to the right of the controls I would like to insert my one of my forms. It must be fixed within its display frame (not moveable or sizeable).

    Sincerely,
    Hansel
    [email protected]


  4. #4
    Guest

    Re: Inserting a Form into Another form

    If I undenrstand correctly it's simple: Set BorderStyle property for your second form to None and display it with statement Form2.Show vbModal, Form1. In Form2_Load event set Left and Top properties to position it in an appropriate place. I'm using this technique very often to display some kind of additional choices, for example the form has Combobox to select the type of customer, but it doesn't have some particular type of customer. Double click on that combo dislays the form which allows to enter a new type of customer. And second method is to create ActiveX control containing all controls you need and to use it instead of regular controls.
    Vlad


  5. #5
    Join Date
    Apr 1999
    Location
    Rotterdam, Netherlands
    Posts
    278

    Re: Inserting a Form into Another form

    Modify the windowstyle of form1 etc. using SetWindowLong and add the WS_CHILD style, then use SetParent to put it in your main form. I usually have a picturebox in which I show the form.
    Something like this:

    public Sub Make_Child_Window(ParenthWnd as Long, ChildhWnd as Long)
    Dim lStyle as Long
    lStyle = GetWindowLong(ChildhWnd, GWL_STYLE)
    lStyle = lStyle Or WS_CHILD
    Call SetWindowLong(ChildhWnd, GWL_STYLE, lStyle)
    Call SetParent(ChildhWnd, ParenthWnd)
    End Sub




    Crazy D :-)
    "One ring rules them all"

  6. #6
    Join Date
    Dec 1999
    Posts
    15

    Re: Inserting a Form into Another form

    Hey:

    Your suggestion is good and useful were one needs to add functionality to a form. However, in my instance, setting the displayed form to modal prevents access to the parent form and so one will not be able to select another form (unless the displayed form is closed).

    I have also tried CrazyD's suggestion, which is more in line with what I require. You should give it a try. Thanks all the same.

    Sincerely,
    Hansel


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

Featured