3

How to display a message box in C# as system modal, something like vbModal in Visual Basic 6?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

5 Answers5

3

Advanced MessageBoxing with the C# MessageBoxIndirect Wrapper

TWA
  • 12,756
  • 13
  • 56
  • 92
2

Are you talking about message boxes, or standard forms? If you're talking about standard forms, the easiest .NET equivalent of vbModal is the ShowDialog method of System.Windows.Forms.Form. So, rather than the old

myForm.Show vbModal

you use

myForm.ShowDialog();

or

myForm.ShowDialog(myFormOwner);

This halts execution at the ShowDialog line just like the old vbModal used to.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dan F
  • 11,958
  • 3
  • 48
  • 72
  • 3
    These are application modal not system modal – ChrisF Jun 24 '09 at 12:11
  • 2
    Yep. He mentioned vbModal, so I'm hoping he doesn't actually *mean* system modal, and more means "on top of all other windows in my app" :-) It's worth a shot anyway, and people searching for vbModal might learn something at the same time. – Dan F Jun 24 '09 at 12:15
1

I think you'll have to roll your own.

A quick search has turned up these two links:

Code Project

Egghead Cafe

ChrisF
  • 134,786
  • 31
  • 255
  • 325
0

You should also be asking yourself if you really want to be creating a system modal message box, its considered bad UI design and that's why its not in .NET out the box.

Mark
  • 2,392
  • 4
  • 21
  • 42
-1

Standard message box in C# is modal (cannot access rest of app until messagebox is dismissed).

http://msdn.microsoft.com/en-us/library/aa335423(VS.71).aspx

"A message box is a modal dialog, which means no input (keyboard or mouse click) can occur except to objects on the modal form. "

Edit: I am not sure about Vb6 and messagebox there. Does it use a different type of "modal"?

Maestro1024
  • 3,173
  • 8
  • 35
  • 52