1

C# WinApp: if I am creating a form at run time How can I tell it to be "Modal" ... I tried mFrmPersons.Modal = true but compile error was saying it is a read only property. so what can I do? Thanks

EDIT: I cannot use Show or Show Dialog! I have a form that some other application is embedding inside it. so the only way I can call my form is like this:

moPersons.NonClinDocDialog.ShowDocs(DocContext);

The only thing I have control over it is moPersons that is the form I am defining in my Application... rest of it a call to other apps...so I want to set the Modal for moPersons

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Bohn
  • 26,091
  • 61
  • 167
  • 254
  • forgot to mention that in the question: I cannot use Show or Show Dialog! I have a form that some other application is embedding inside it. so the only way I can call my form is like this: moPersons.NonClinDocDialog.ShowDocs(DocContext); so the only thing I have control over it is moPersons that is the form I am defining in my Application... rest of it a call to other apps...so I want to set the Modal for moPersons – Bohn Jan 03 '11 at 18:47
  • You could edit the question to reflect this :) – NickAldwin Jan 03 '11 at 18:48
  • 1
    You can only simulate a modal dialog if you can get an event when the form is closing (not closed). – Hans Passant Jan 03 '11 at 18:54
  • I'd try to fake it... Perhaps show another form in the loading etc – Marc Gravell Jan 03 '11 at 19:24

2 Answers2

2

Using ShowDialog() instead of Show() might work.

NickAldwin
  • 11,584
  • 12
  • 52
  • 67
  • yes forgot to mention that in the question: I cannot use Show or Show Dialog! I have a form that some other application is embedding inside it. so the only way I can call my form is like this: moPersons.NonClinDocDialog.ShowDocs(DocContext); so the only thing I have control over it is moPersons that is the form I am defining in my Application... rest of it a call to other apps...so I want to set the Modal for moPersons – Bohn Jan 03 '11 at 18:45
1

The trick is deciding whether the code shows the form with theForm.Show() vs theForm.ShowDialog() - so it is the code that displays the form that needs tweaking.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • yes forgot to mention that in the question: I cannot use Show or Show Dialog! I have a form that some other application is embedding inside it. so the only way I can call my form is like this: moPersons.NonClinDocDialog.ShowDocs(DocContext); so the only thing I have control over it is moPersons that is the form I am defining in my Application... rest of it a call to other apps...so I want to set the Modal for moPersons – Bohn Jan 03 '11 at 18:46