Search code examples
c#winformsmessagebox

how to show image on form like MessageBoxIcon.Stop image


How to show image on form like MessageBoxIcon.Stop image in WindowsFormsApplication in c# 2008


Solution

  • You can use one of the icons from the SystemIcons class.

    The linked MSDN article has an example.

    It's not a very good example, as (a) it doesn't Dispose the Bitmap it creates, (b) it doesn't use try/finally to ensure the Graphics object it creates is Disposed in the event of an Exception, and (c) a button click event handler is not the right place to be drawing.

    I would handle the Form's Paint event, and draw it as follows:

    private void MyForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        e.Graphics.DrawIcon(SystemIcons.Error, 16, 16);
    }