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)?
Custom WinForm with MessageBox Icon and Sound
Asked Answered
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();
Just wanted to add that this was a nice reference for drawing the system icon: codeproject.com/script/Articles/ViewDownloads.aspx?aid=154680 –
Olibanum
You need to use Graphics.DrawIcon(), or some variation, as SystemIcons returns Icon, not Image, but you're essentially there. –
Olibanum
@StealthRabbi Oops. Updated code. Yes,
DrawIcon
or use the ToBitmap()
function. –
Chalcopyrite MessageBox is provided by the OS I'm afraid. You can extend it, but it requires a lot of work (see this CodeProject article for a tutorial). Your best bet is probably to start again with a control inheriting from Form as you suggest.
To access the icons, it's as simple as using the System.Drawing.SystemIcons
class (documentation for that is here.)
© 2022 - 2024 — McMap. All rights reserved.