Solved

MdiChild form cannot ShowDialog

Posted on 2004-09-07
12
1,730 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

12 Experts available now in Live!

Get 1:1 Help Now