3

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?

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • No, is not a duplicate, that question is about a file containing resources, and answers says the location of the file. I'm asking whether other Windows icons/images can be accesed directlly like using the SystemIcons Class. – ElektroStudios May 01 '14 at 19:56
  • Then what is your question? _"How to use bitmaps from DLLs"_? See [How can I use the images within shell32.dll in my C# project?](http://stackoverflow.com/questions/6872957/how-can-i-use-the-images-within-shell32-dll-in-my-c-sharp-project). If your question is _"What other classes exist in the BCL that contain icons?"_, then I think it is a bit too broad. – CodeCaster May 01 '14 at 19:58
  • My question `Exist more Classes to use predefined Icons/Images in .NET Framework like the SystemIcons Class?`. PS: Really thanks for that link about Shell32.dll, seems very usefull!, If you would like to put that comment in an answer (and also clarifying the question of the Classes) I would like to mark your answer as the accepted one, thanks, and sorry for my English. – ElektroStudios May 01 '14 at 20:00
  • 2
    what is the big advantage of extracting an image from a MS DLL vs including the same image as a resource in your app? – Ňɏssa Pøngjǣrdenlarp May 01 '14 at 20:06
  • @Plutonix Yes I could include the single images as resources in the template, is the easiest thing to solve the issue, but I never hurts to learn something new and interesting, and this detail about Framework Classes that points to MS Images/Icons seems interesting to me, I just would like to know the answer to that, thanks for your comment. – ElektroStudios May 01 '14 at 20:10
  • In what thing thinks the moderator who titled my question as "This question already has an answer here:"? really that question has an answer about what I'm asking for? ...of course it has not. please, moderator, read the content of my question before judge. I'll repeat again for third time my question: `Exist more Classes to use predefined Icons/Images in .NET Framework like the SystemIcons Class?` – ElektroStudios May 02 '14 at 08:03
  • And I'll repeat it again: `Exist more Classes to use predefined Icons/Images in .NET Framework like the SystemIcons Class?`, then what have my question in common with a question titled `Location of .NET ToolStrip Standard Icons` and it's answers?, NOTHING of NOTHING 'cause I'm not asking for a file location, I'm asking about the existance and usage of Classes. – ElektroStudios May 02 '14 at 08:10
  • `This question has been asked before and already has an answer.` seems really ridiculous all the people who voted that only for voting instead of answered 'cause they didn't read the question or they didn't know the solution. well, thanks for read. – ElektroStudios May 02 '14 at 08:15
  • 1
    @ElektroStudios makes sense to me. This does NOT appear to be a duplicate question to me. CodeCaster seems adversarial from the first comment. – David Tansey May 03 '14 at 12:35
  • .NET does not have any pre-defined icons. The class you refer to is specific to WinForms and just grant access to the Windows built-in icons, a limited set. Just use a resource file. – H H May 03 '14 at 12:38
  • @Henk Holterman that's the only thing that I've asked and I don't know why all this fight from everybody to answer a simple thing that never get asked in S.O., no matter if in the question I get a missunderstanding about how it works, the important thing is that it never get asked!, thanks for solve my issue. – ElektroStudios May 03 '14 at 12:41
  • 1
    The Close here does seem a little hasty. – H H May 03 '14 at 12:56

1 Answers1

0

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
Pieter de Vries
  • 825
  • 7
  • 18