The Requirement... I've a massive VB6 Project with tons of forms in it. One parent MDI form and all other forms open inside it from different menu actions.
I need to split this project, say keep the main form there, and extract other groups of related forms into their own projects.
Lets take example of a fresh project... MainProject:
- Only one MDI form called, frmMain with menu
- Menu Item 1
- Menu Item 2
prjModule1
- To have a form frmModule1Main, which needs to be loaded as MDI child of frmMain when menu item 1 is selected
prjModule2
- To have a form frmModule2Main, which needs to be loaded as MDI child of frmMain when menu item 2 is selected
How can I achieve this, what should be the project types of each project? the main one I understand should be Standard Exe, but what about the other two? Do I need exe or dll?
I tried the following
Standard Exe project: MainProject, with one MDI parent form DLL Project child1:
- Has a public a public class, and a form.
- exposed a method from Class "ShowForm"
- In the MainProject, added a reference to the child1 project
- Invoked ShowForm on menu click
Private Sub mnuModule1_Click()
Dim cls As New prjModule1.Class1
cls.ShowForm
End Sub
and this is the ShowForm sub
Public Sub ShowForm()
Dim localForm As New frmModule1Main
localForm.Show
End Sub
When I select the Module1 menu item, the form prjModule1.frmModule1Main opens as expected. But is not the child of main MDI form. If I change the MDIChild property of frmModule1Main to True. I get the error "No MDI form available to load"
What am I missing, how can I tell the child form who is your MDI parent? And that it is already loaded?
As was pointed out in the comments, you need to convert your Forms to UserControls and embed those UserControls in a project of type ActiveX Control. I could not get any other combination to work.
In the code snippet, frmChild is a MDIChild Form with no controls on it. When you want to show a "form" contained in another project you dynamically add that "form" to frmChild. Here Project1 is adding a "form" from Project3: