1

I need to keep message box inside a parent form. So when the user tries to move Messagebox outside parent it stays within parent from. I have no problem doing my own message form. But I like to use Message box functionality.

Ideally I would like to add to this approach. center MessageBox in parent form

How do I capture messagebox move event and not allow it to go outside parent.

Community
  • 1
  • 1
Andrew Rokicki
  • 202
  • 2
  • 9
  • I suppose you could use this code and just keep it running: http://stackoverflow.com/questions/2576156/winforms-how-can-i-make-messagebox-appear-centered-on-mainform/2576220#2576220 One feature too many, frankly. – Hans Passant Jun 13 '12 at 19:54

1 Answers1

2

The way to achieve this is to create your own MessageBox class, and duplicate the functionality.

As a hint: It may help to use a label with an "autosize" turned on. You can then use the size of the label to resize the MessageBox to match.

Having said that, it sounds like a bad idea. Why not just let the user move the messagebox if they want?

Ben
  • 34,935
  • 6
  • 74
  • 113
  • Agreed why not let the user move the messageBox? – General Grey Jun 13 '12 at 19:31
  • My concern is if the user moves MessageBox away from the main form and comes back to main from later forgetting that MessageBox is somewhere else, my application will seem unresponsive. – Andrew Rokicki Jun 13 '12 at 19:33
  • I could just let them move the message box (possibly I am making too much out of this). I understand that if the user clicks on parent message box pops back up, but on WinXp it could be hidden by a task bar. – Andrew Rokicki Jun 13 '12 at 19:40
  • 1
    All apps with messagebox's work this way, so yours is nothing different. I wouldn't worry about it. – Joel Lucsy Jun 13 '12 at 19:49