Solved

MdiChild form cannot ShowDialog

Posted on 2004-09-07
12
1,699 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
  • 7
  • 4
12 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
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
Comment Utility
What are you trying to achieve ?

There maybe a solution using the api call SetWindowPos
0
 

Author Comment

by:LKearney
Comment Utility
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
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
tree lines is ofcourse three lines :-)
0
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
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 45 total points
Comment Utility
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
Comment Utility
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 80 total points
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now