Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override WinForms MessageBox Control

All, I understand that for extensively customised dialogs I would need to create my own form and ShowDialog(). However, in my current case I would just like to extend the MessageBox class to facilitate a CustomMessageBox that is capable of showing different icons insted of those determined by the system.

I have not overridden such a control before and I am not even sure where to start. Could someone point me in the right direction?

Thanks for your time.

like image 968
MoonKnight Avatar asked Mar 15 '13 13:03

MoonKnight


People also ask

How to override MessageBox show in c#?

No, you cannot override MessageBox. Show because it is a static method.

Which of the following is default button of MessageBox control?

MessageBox with Default Button By default, the first button is the default button. The MessageBoxDefaultButton enumeration is used for this purpose and it has the following three values. The following code snippet creates a MessageBox with a title, buttons, and an icon and sets the second button as a default button.

What is the namespace for MessageBox in C#?

Message Box is a class in the “Systems. Windows. Forms” Namespace and the assembly it is available is “System. Windows.


2 Answers

MessageBox is not a control actually (doesn't inherit from Control), it's just a class.

Actually, it's even almost a static class, as there is no public/protected constructor defined, and only static methods. It's more like a factory.

You probably should write your own, as it's not extendable.

like image 108
ken2k Avatar answered Oct 23 '22 03:10

ken2k


You can't customize MessageBox like that, unfortunately. You will have to roll-your-own.

like image 27
Matthew Watson Avatar answered Oct 23 '22 03:10

Matthew Watson