Thei Posted April 29, 2008 Posted April 29, 2008 Hi all, I've got a MDIParent Form (frmMain) from which I launch a MDIChild Form (frmMDI_1). Now I want to launch the second MDIChild Form (frmMDI_2) from within the first MDIChild Form. The MDIParent of the second MDIChild Form should also be frmMain. I tried to do this as shown below 'Inside a Module Public WithEvents MainForm As frmMain Public WithEvents Child1 As frmMDI_1 Public WithEvents Child2 As frmMDI_2 'Inside the frmMDI_1 Form Child2 = New frmMDI_2 With Child2 .MdiParent = MainForm .Show() .WindowState = FormWindowState.Maximized End With When the code above is ran the frmMDI_2 Form is not shown as a MDIChild but as a normal form. What am I doing wrong? Thanks Quote
joe_pool_is Posted April 30, 2008 Posted April 30, 2008 Could you signal the MDIParent Form from the first MDIChild Form with a custom method within the MDIChild?Class frmMain Public Function ParentShow(nForm as Integer) As Integer If (nForm = 1) Then If (Child1 Is Nothing) Then Child1 = New frmMDI_1 With Child1 .MdiParent = MainForm .WindowState = ForWindowState.Maximized .Show() End With Return 1 ' Can be interpreted as a True Else Return 0 ' Can be interpreted as a False End If Else If (nForm = 2) Then If (Child2 Is Nothing) Then Child2 = New frmMDI_2 With Child2 .MdiParent = MainForm .WindowState = ForWindowState.Maximized .Show() End With Return 1 ' Can be interpreted as a True Else Return 0 ' Can be interpreted as a False End If Else Return -1 ' Signal an error End If End Sub End ClassAlso, you may want to play around with the order that you call Show() and WindowState. I had some problems with them recently where I was attempting to hide an application in the task bar tray, and it turned out I wasn't calling the methods in the right order. It wasn't documented anywhere that I could find, though. Hope this helps. Quote Avoid Sears Home Improvement
Thei Posted May 5, 2008 Author Posted May 5, 2008 I tried to use the function that you suggested but, although no error is raised, no form is being displayed. Quote
Administrators PlausiblyDamp Posted May 5, 2008 Administrators Posted May 5, 2008 What is the value of MainForm when you are running the above code? Would it be possible for you to attach a very simple project that shows this problem? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Thei Posted May 5, 2008 Author Posted May 5, 2008 This is very odd. When I made a new project and used code simular to the code above it worked fine. But in my excisting project it still doesn't work. I've attached the test project to this post.mdi_test.zip Quote
Administrators PlausiblyDamp Posted May 5, 2008 Administrators Posted May 5, 2008 I would try stepping through your original code to check it is doing the same things as the attached sample. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Thei Posted May 5, 2008 Author Posted May 5, 2008 Strangely enough that is the case. That's why I don't understand that no form is shown. Quote
Administrators PlausiblyDamp Posted May 5, 2008 Administrators Posted May 5, 2008 If you step through the code are the actual variables and the MDIParent properties all being set to valid values? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Thei Posted May 6, 2008 Author Posted May 6, 2008 They seem to be valid. MDIParent = {PROJECTNAME.frmMain} When I display a MsgBox after the Show method it also shows the right MDIParent (frmMain). With MDI_1 .MdiParent = Me .Show() .WindowState = FormWindowState.Maximized MsgBox(.MdiParent.Name) End With Quote
joe_pool_is Posted May 6, 2008 Posted May 6, 2008 Shouldn't you be creating a new instance of the form?MDI_1 = New frmMain() With MDI_1 .MdiParent = Me .Show() .WindowState = FormWindowState.Maximized MsgBox(.MdiParent.Name) End With Quote Avoid Sears Home Improvement
Thei Posted May 6, 2008 Author Posted May 6, 2008 Shouldn't you be creating a new instance of the form?MDI_1 = New frmMain() With MDI_1 .MdiParent = Me .Show() .WindowState = FormWindowState.Maximized MsgBox(.MdiParent.Name) End With Yes that's right. I forgot to paste that part into this post. Quote
Thei Posted May 6, 2008 Author Posted May 6, 2008 I've found the problem. Before the MDIParent form is being shown the user has to log in. This is done using a loginform. In the properties of the project I set that loginform as startup form, and I changed the option Shutdown Mode to When Last Form Closes. After I changed these settings in the test project that I attached to this post no MDI form was shown when the button was clicked. The code used to show the MainForm from inside the LoginForm is like the one below. Dim frm As New frmMain frm.Show() Me.Close Yet when I change that code to this frmMain.Show() Me.Close it works. Although very happy that it finally works, I'm quite curious to why it didn't work using the first method of showing the MainForm. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.