Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom WinForm with MessageBox Icon and Sound

I want to create a modal dialog that has more controls than what a standard .NET MessageBox offers you. I've created my own Windows Form that will be called with ShowDialog() to give the modal behavior. However, I'd like to utilize the graphics that come with MessageBox via MesageBoxIcon. Is this possible? Is it also possible to replicate playing the error/warning windows sounds associated with the message box icons (as they are set in the user's windows settings)?

like image 277
Stealth Rabbi Avatar asked Mar 28 '12 16:03

Stealth Rabbi


People also ask

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.

How to display Message box icon in C#?

To display a message box, call the static method MessageBox. Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.

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.


1 Answers

See System.Drawing.SystemIcons class to display the system icons the MessageBox class uses, such as Question, Information and Warning.

e.Graphics.DrawImage(SystemIcons.Question.ToBitmap(), new Point(0, 0));

For the sounds, see the System.Media.SystemSounds class to play the associated sounds.

System.Media.SystemSounds.Asterisk.Play();
like image 92
LarsTech Avatar answered Sep 18 '22 14:09

LarsTech