Windows Develop Bookmark and Share   
 index > Windows Forms General > MDI Forms
 

MDI Forms

Okay just a quick question, and hopefully a quick solution.  I currently have a main mdi form and two child mdi forms.  My objective is to get one of the child forms to open through a button click on the other.  So say the user runs the program, they see a blank form, then they click on a button and one of the child forms opens.  Inside that form is another button that is supposed to open another child form, but who's parent is the main form.  My problem is, this doesn't happen.  The form doesn't open, and nothing appears to happen.

Here is my code:

--MAIN FORM--
    Public Sub LoadMDIChild(ByVal NewMDIChild As Form)
        If NewMDIChild Is Nothing Then
            NewMDIChild.MdiParent = Me
            NewMDIChild.Dock = DockStyle.None
        End If
        NewMDIChild.Show()
        NewMDIChild.BringToFront()
    End Sub

--SUB1--
    Dim frmViewAll As New frmViewAll()   
    Dim frmMain as new frmMain()
    frmMain.LoadMDIChild(frmClientsViewAll)

If anyone could help it would be greatly appreciated.

Thanks,

Dave
MigrationUser 1  Tuesday, May 20, 2003 7:58 AM
Looks to me like you're creating a new instance of frmMain, and having that HIDDEN form create an instance of the second child form. You'll need some sort of "global" reference to the main form available.  The only easy way I know of to do that is to add a module to your project, insert a Public Sub Main, like this:

  Public frmMain As New frmMain

  <STAThread()> _
  Public Sub Main()
    Application.Run(frmMain)
  End Sub

(You can do the same thing with a Shared Sub Main in a class, as well.)

Then, when you need to create the new frmClientsViewAll, just refer to the existing frmMain variable exposed in your new module. 
MigrationUser 1  Tuesday, May 20, 2003 12:29 PM
Yup, that sure did it.  Thanks very much, I can't believe I didn't realize that (I've been looking at it all morning)... could be the lack of Caffene...

Dave
MigrationUser 1  Tuesday, May 20, 2003 12:56 PM

You can use google to search for other answers

Custom Search

More Threads

• RunTime Change of DataGridView Size
• Passing data from one form to the next??
• Virtual Earth control - works in VB - not in C# "'Window.External' is null or not an object"
• Inherited Form in dll doesn't work with Smart Device
• multiline text in listview ?
• Problems with gif image in tablelayout panel
• question about updating GUI components from a seperate thread.
• Best way to work with listboxes
• Problem with symbols when drawing Hebrew text by Graphics.DrawString function from the RichTextBox control
• Clipboard Clear