Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a standard error icon be shown in on a C# windows forms dialog?

Tags:

c#

winforms

I'd like to use the standard error icon (Standard Icons) on a Windows Forms dialog. How can the error icon be loaded into an Image for display?

like image 579
Jonathan Wright Avatar asked Feb 01 '11 21:02

Jonathan Wright


2 Answers

I have to sputter at the horrid waste of burning up such expensive resources as a Control and a Windows window, just to draw a dinky icon. To save one line of code:

    protected override void OnPaint(PaintEventArgs e) {
        e.Graphics.DrawIcon(SystemIcons.Error, 10, 10);
        base.OnPaint(e);
    }
like image 160
Hans Passant Avatar answered Nov 05 '22 17:11

Hans Passant


If you're using Visual Studio's Designer, add a PictureBox object. Then in code, set your PictureBox's Image property:

dialog.PictureBox.Image = SystemIcons.Error.ToBitmap();
like image 45
Ron Avatar answered Nov 05 '22 16:11

Ron