Question

I'm writting my own 'Error Dialog' to handle exceptions on my Forms, I would like to create a template Item of this Dialog and I'm gonna use some images in the Dialog but I don't want to fill the template with external resources.

enter image description here

For the PictureBox I'm using the SystemIcons Class to get and display the Error Bitmap.

PictureBox_Error.BackgroundImage = SystemIcons.Error.ToBitmap 

But as you can see I need more resources for each ToolStripButton of the image above.

Then my question is:

Exist more Classes to use predefined Icons/Images in .NET Framework like the SystemIcons Class?, if not, What could be the better way to access/retrieve the Bitmaps stored in Windows resource dll's as Shell32.dll (which stores all the icons that I need)?, using API or managed code?, which API? ...or which native Class?

Was it helpful?

Solution

You could do it like this. Google is full of answers you know. You might have to add some references. Just right click on the error if there is one.

http://msdn.microsoft.com/en-us/library/system.drawing.icon.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

C#

 private void IconToBitmap(PaintEventArgs e)
    {
        // Construct an Icon.
        Icon icon1 = new Icon(SystemIcons.Exclamation, 40, 40);

        // Call ToBitmap to convert it.
        Bitmap bmp = icon1.ToBitmap();

        // Draw the bitmap.
        e.Graphics.DrawImage(bmp, new Point(30, 30));
    }

vb.net

Private Sub IconToBitmap(ByVal e As PaintEventArgs)

    ' Construct an Icon.'
    Dim icon1 As New Icon(SystemIcons.Exclamation, 40, 40)        

    ' Call ToBitmap to convert it.' 
    Dim bmp As Bitmap = icon1.ToBitmap() 

    ' Draw the bitmap.'
    e.Graphics.DrawImage(bmp, New Point(30, 30))         

End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top