0

Coming up to speed with C# over iterations of some projects. Many times concepts I search for have different answers than I expected, but it teaches me ultimately more about the Windows API and some of the reasons for its structure.

I did a recent search for "C# control size and location of message box" and one of the results was a 2 year old thread:

How to change the size of MessageBox in c#?

Which also references yet an older thread.

OK, I get the answers "Not possible, you should create your own form for this" followed by some examples and/or guidance.

In this particular case, I disagree and do not see the intent of the class designer.

Another natural result of my search was the Show() method for the MessageBox class. This led me back to the class where I find that there are nineteen overloads for the Show() method. None of which have to do with geometry; which I feel may be quite simple.

My point is the features of the various Show() methods allow a programmer to opt for the icon, the title text, the content text, as well as the buttons. I see it's even integrated with the Help Navigator. This is an incredible amount of built-in flexibility for the widget, but meanwhile I can't control the size and location of that widget? This is really 4 numbers: X, Y, x-depth, y-depth.

I fully understand that I could create a new form, or maybe class(?) to do this for me. Actually, that bears the simplification question. Sure ... I can create a whole form. That means I have to manage that and deal with it as well as provide methods for it by my own rite. What if I were to create a class using the MessageBox class as my base? I have to say that I'd have to wander a bit to see if I could make a new Show() method that had the overloads for X/Y/x-depth/y-depth.

These overall functions are very natural things to do, IMHO. Pop-Up a notification. Title that box to show ERROR or WARNING, have added explanation text included within the box. Have the capability to have OK and/or CANCEL in that box. I'm therefore wondering why the designers chose to limit the capability and not allow for size and position of the pop-up? Because a default result is the box gets put wherever the system decides, and it's ugly/small or large depending on the content.

My final wonder is whether prevailing opinions would be that I ought to make my own custom form, or if I'd actually be successful at making a class which inherits MessageBox and making a custom Show() method which supported geometry.

Perhaps even beyond that: Am I mistaken? Has this class been updated to satisfy my needs and I just don't yet know this?

Community
  • 1
  • 1
rtm
  • 81
  • 1
  • 9
  • MessageBox is not sealed, so yes you could derive your own class from it, but to what purpose? You still will be unable to change the position and size of the base class MessageBox. If you have time to waste go for your own custom form that acts as a MessageBox. See this discussion https://social.msdn.microsoft.com/Forums/en-US/c4fcd52d-1e65-4be0-be9b-c96d5b0448dc/is-it-possible-to-override-the-messagebox-class?forum=Vsexpressvcs – Steve Nov 20 '14 at 18:40

1 Answers1

1

No, MessageBox does not allow specifying a size because the underlying Win32 API does not allow it either.

Not possible, you should create your own form for this" followed by some examples and/or guidance.

That is correct, whether or not you agree it is a good idea or not does not change the fact that message boxes do not support positions and sizing. They are meant to be quick, simple, primitive things that do little, but might get the job done. Any more than that requires a form. I suppose while you might want sizing, others might want transparency, or even the ability to change the text on the buttons (you can only choose from a selection) - it can't make everyone happy. At that point you've pretty much come to the need for a form.

vcsjones
  • 138,677
  • 31
  • 291
  • 286