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)?
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.
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.
Message Box is a class in the “Systems. Windows. Forms” Namespace and the assembly it is available is “System. Windows.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With