?
Solved

MdiChild form cannot ShowDialog

Posted on 2004-09-07
12
Medium Priority
?
1,883 Views
Last Modified: 2011-09-20
Hi,

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
ChildForm1.ShowDialog()

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.
0
Comment
Question by:LKearney
[X]
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
12 Comments
 
LVL 25

Expert Comment

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

you could just do

ChildForm1.Show()

or not make it a mdi child

Dim ChildForm1 As New Form2
ChildForm1.ShowDialog()
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11995816
What are you trying to achieve ?

There maybe a solution using the api call SetWindowPos
0
 

Author Comment

by:LKearney
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!!

Larry
0
Industry Leaders: 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

by:RonaldBiemans
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
0
 

Author Comment

by:LKearney
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"??

Larry
0
 
LVL 25

Expert Comment

by:RonaldBiemans
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.

0
 
LVL 25

Expert Comment

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

Expert Comment

by:RonaldBiemans
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
0
 
LVL 5

Assisted Solution

by:Jojo1771
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:

MDI PARENT

 Dim child6 As New LogonForm
   child6.reftologon = Me
   child6.Show()

END PARENT

LOGON FORM
 '  Load of Form
   reftologon.Visible = False
        reftologon.Hide()

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

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


END LOGON

Just one way to do it.

0
 

Author Comment

by:LKearney
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??

Larry
0
 
LVL 25

Accepted Solution

by:
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
0
 

Author Comment

by:LKearney
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!!

Larry

0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

801 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