Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

Keeping Non-MDI forms within a Main form?

I am using non-MDI forms in my application only because the ability to add a MDI form has been disabled in the Project menu (don't know why either). Anyway, I have an active main form and when I show a new form....I wish for it to remain in the main form. I've seen an example of this before but can't remember where.

Thanks!
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

You can make a form a pseudo-mdi child using the SetParent() API:

Option Explicit

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
   
Private Sub Command1_Click()
    Dim f2 As New Form2
    f2.Show
    SetParent f2.hWnd, Me.hWnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim f As Form
    For Each f In Forms
        Unload f
    Next f
End Sub
ASKER CERTIFIED SOLUTION
Avatar of sivachirravuri
sivachirravuri
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial