MdiChild form cannot ShowDialog

Posted on 2004-09-07
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!!

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 45 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 80 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using 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 …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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