Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


MdiChild form cannot ShowDialog

Posted on 2004-09-07
Medium Priority
Last Modified: 2011-09-20

First, thanks for clicking.

Have a ParentForm - Form1 - have set MidContainer = True
Have a ChildForm - Form2

Have a button on Form1 that has this click event

Dim ChildForm1 As New Form2
ChildForm1.MdiParent = Me

When I run it crashes at ShowDialog with this error

"Forms that are not top level forms cannot be displayed as a modal dialog. Remove the form from any parent form before calling showDialog."

Does anyone know how to get around this error?? Your opinions would be most grateful appreciated.

Please note this is a simple sample application that simulates the issue in my main application that has many child forms within one parent form.
Question by:LKearney
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
LVL 25

Expert Comment

ID: 11995776
Hi Lkearney, There is no solution mdi children can't be show as dialog.

you could just do


or not make it a mdi child

Dim ChildForm1 As New Form2
LVL 25

Expert Comment

ID: 11995816
What are you trying to achieve ?

There maybe a solution using the api call SetWindowPos

Author Comment

ID: 11995968
Hi Ronald,

Thanks for your posts.

Unbelievable!!!  Microsoft offer a Mdi system but don't allow for simply showing a childform in modal dialog.

Here's an example of what I'm trying to achieve. If you think about this it's a generic requirement of any software system.

Have a main menu (Frm_MainMenu) that has mdiContainer set to TRUE. This has the typical menubar of any MdiParent form, allowing the option of opening many childforms within the Parent form.

This Parent Form then opens a Logon Form (Frm_Logon) in it's Form_load event, which we obviously want it to be contained within the MainMenu Parent form.
Furthermore, we want to show it in DialogMode because we don't want the Logon page to be bypassed.

Hence the very simple and generic requirement of showing a child form in Dialog mode.

Hope this was a good example.

Any ideas on a way around this issue Ronald??

Thanks for your support!!

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 25

Expert Comment

ID: 11996029
Hi Larry,

How would they bypass the login screen ? Just make sure they can't open any other form, maybe by disableling the menuitems, and reenable them again when the login is succesfull

Author Comment

ID: 11996153
Hi Ronald,

I have a lot of 40+ menuItems and have 100+ childforms in our application. I also have a dockable toolbar down the left with icons on it for easy access of the most used child forms by the user.

Recognise what your saying, but don't think that's a solution in our application. Too many menuitems and toolbars.

There must be some solution to this since how many software companies have a simple Logon page appearing as the first form within a parent mainmenu. It's first level security!

Hope you recongnise why disabling all the controls on the Mainmenu and reenabling them would really be suitable for our needs.

What about the "api call SetWindowPos"??

LVL 25

Expert Comment

ID: 11996237
Hi Larry, Well the setwindowPos would not work for you either because that will only keep the form on top, but you would still be able to click the other controls.

Bye the way, disabling the menuitems regardless of how many there are, is still only tree lines of code, and disabling the toolbar only one.

LVL 25

Expert Comment

ID: 11996240
tree lines is ofcourse three lines :-)
LVL 25

Expert Comment

ID: 11996322
And since you only have to disable the top menuitems (I don't think that there or 40 top items) , It won't have any impact on performance either

Assisted Solution

Jojo1771 earned 135 total points
ID: 11997717
I have created many applications  with logon screens, I always find it best not to make them a child. I usually have my MDI parent as startup for various reasons, but when the application, loads, I hide the MDI parent and show the Logon form. Then once they can be authinticated. I then show the parent and hide logon or dispose of it. Or you could simple disable MDI parent.  But this always prevents the user from bypassing logn...
Heres some sample code used for  diffrent apps:


 Dim child6 As New LogonForm
   child6.reftologon = Me


 '  Load of Form
   reftologon.Visible = False

'Close of form if logged in
        reftologon.Visible = True
        reftologon.WindowState = FormWindowState.Maximized
        reftologon.Enabled = True

'Close of form by any other way
'call this in the form closing sub
    Call reftologon.Close()


Just one way to do it.


Author Comment

ID: 11998526
Hi Ronald and jojo1771

Thanks for your posts!!

Problem is it's not just the Logon form that needs to be dialog mode. Logon form was used as an example to keep the undertanding simple. We also have several forms that need to appear in Dialog mode (e.g. Wizards, forms that need to be dialog to preserve the data integrity of our DB tables etc.) Furthermore, for the users ease, some other forms need to be seen but not changable. hence the requirement for child forms to appear as dialog.

Hope you understand my requirements. Is it an error from Microsoft that the child form cannot be show in dialog mode, or by design??

LVL 25

Accepted Solution

RonaldBiemans earned 240 total points
ID: 12003793
Hi Larry, than the only option you have left is don't make them MDI children, as you can see in other mdi applications, like Excel or Word, the wizards there  aren't MDI children either

Author Comment

ID: 12008974
Hi Ronald, (and jojo1771)

Your right, Sage also has wizards etc. in non dialog mode. Also, tried in vb6 and when try and Show vbmodal, it causes the same error.

So it seems for whatever reason they've designed it that way. Fair enough, it can't be that important to have as dialog since it's never bothered me with other apps anyway (e.g. Sage or Excel for example)

Thanks for persisting with this post. I have split the points in some recognition of both your efforts in helping me out. It is much appreciated!!



Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question