2

I need to open modal form (frmD) from MdiChild (frmB) form without blocking main form (frmA) and all others opened MdiChild forms (frmC). Then i switch to frmC the frmD is hidden.

This is the similar question, but not for Mdi application.

Is there a way to open a modal dialog and only have it block the mdi child form that opened it?

Community
  • 1
  • 1
referee
  • 106
  • 3
  • 9
  • 1
    you missed the link "This is".. correct it – Shekhar_Pro Jan 18 '11 at 09:31
  • 1
    What was wrong with using the `Show` method (rather than `ShowDialog`) and setting the MDI child form's `WS_DISABLED` style flag using P/Invoke, as suggested by [P Daddy's excellent answer](http://stackoverflow.com/questions/428494/is-it-possible-to-use-showdialog-without-blocking-all-forms/428782#428782) to the "similar question"? – Cody Gray - on strike Jan 18 '11 at 10:01
  • And what should the MDI commands Cascade, Tile and Minimize-All do when your dialog is up? – H H Jan 18 '11 at 10:04
  • Cody Gray, in principle suitable...1) how can i positioning the modal forms only at center of its disabled parent? 2) how to set focus to modal after clicking on its parent? – referee Jan 18 '11 at 11:02
  • Henk Holterman, mdi layouts work correct – referee Jan 18 '11 at 11:04

1 Answers1

0

One possible strategy is described in this article, which relies on using the .Show() method instead of .ShowDialog() to open the modal dialog and setting the MdiChild's Enabled property to false just before you call the .Show() method.

You then need to set the Enabled property of your MdiChild back to true when the dialog is closed, which means that you will need to create an event handler in your MdiChild form to handle the FormClosing event of the dialog.

Jazza
  • 1,042
  • 1
  • 9
  • 22
  • 1
    The problem with simply setting the child form's `Enabled` property to false is that all of its controls will take on a disabled appearance (that is, they will look grayed out). Considering that's not how modal dialogs behave in Windows, your application is going to be confusing to users. But there's a better solution that I already suggested in a comment; see [P Daddy's answer](http://stackoverflow.com/questions/428494/is-it-possible-to-use-showdialog-without-blocking-all-forms/428782#428782) to the question linked to by the OP. – Cody Gray - on strike Jan 18 '11 at 10:07
  • You make a valid point - the answer given by @P Daddy is very comprehensive. – Jazza Jan 18 '11 at 11:08