none
how to create .ico file?

    Question

  • Hi, it seems with visual studio 2005, we can create .ico files as required.

    However, I do not know how to realize that.

    A very very simple question...

    Any help?

    Tuesday, August 22, 2006 3:41 AM

Answers

  • yes you can convert an image to an icon file type

     

    Image theImage = Image.FromFile("filename.bmp");

    Bitmap theBitmap = new Bitmap(theImage);

    theBitmap.Save("newfileName.ico", System.Drawing.Imaging.ImageFormat.Icon);

     

    does this help?

    Tuesday, August 22, 2006 4:48 AM
    Moderator
  • ico file for your application or do you mean save an image into an icon?

    if it is an icon for your application, simply add an Icon file into your solution (Right click your project in the solution explorer > add > new item > Icon File

     

    then design your icon within the "mini" editor or create your own application icon in some other software and add it into this solution (in the same way as above but select add existing item) and make sure that the icon size is 32x32.

     

    Then you can set the application icon in code:

     

    this.Icon = new Icon("MyIcon.ico");

     

    when the application is starting up, say at Form_load

     

    does this help?

    Tuesday, August 22, 2006 3:56 AM
    Moderator

All replies

  • ico file for your application or do you mean save an image into an icon?

    if it is an icon for your application, simply add an Icon file into your solution (Right click your project in the solution explorer > add > new item > Icon File

     

    then design your icon within the "mini" editor or create your own application icon in some other software and add it into this solution (in the same way as above but select add existing item) and make sure that the icon size is 32x32.

     

    Then you can set the application icon in code:

     

    this.Icon = new Icon("MyIcon.ico");

     

    when the application is starting up, say at Form_load

     

    does this help?

    Tuesday, August 22, 2006 3:56 AM
    Moderator
  • I was wondering if it was possible to have a regular image converted to an Icon when it was compiled.  I think you can do it in Java so I was wondering if u could do the same in C#.
    Tuesday, August 22, 2006 4:39 AM
  • yes you can convert an image to an icon file type

     

    Image theImage = Image.FromFile("filename.bmp");

    Bitmap theBitmap = new Bitmap(theImage);

    theBitmap.Save("newfileName.ico", System.Drawing.Imaging.ImageFormat.Icon);

     

    does this help?

    Tuesday, August 22, 2006 4:48 AM
    Moderator
  • Thans a lot!

     I want to convert a .jpeg/.gif/.btm file to .ico file and use it in my application.

    I'll try your method.

     

    Well, may I convert .btm file to .ico in the mini icon editor in visual studio 2005?

    Then I can save the icon file to my pc and reuse it when required.

    I do want to show it only in some particular examples using the above code at loarding the form.

     

    Tuesday, August 22, 2006 6:28 AM
  • Thank you that is exactly what I was looking for.
    Tuesday, August 22, 2006 8:28 AM
  •  

    The icon (.ico) file created by the above code, does not show up in explorer and also in any visual studio.

    I think the format of such an icon is different than normal windows icon.

    Thursday, November 29, 2007 10:56 AM
  • ahmedilyas,

    nice compact and easiy to use Code. Good work. Thank you

     

     

    One caveat though, the input bmp file shoudl 32x32 pixel and no more than 256 colors. otherwise VS 2008 will reject the resulting ico even though it may look ok in explorer.

     

     

    I guess that is proabaly some  "assumed should have knowledge" but I sure did not know until I used the wimage editor from sybase.

    Sunday, January 27, 2008 5:16 AM
  • Image theImage = Image.FromFile("filename.bmp");

    Bitmap theBitmap = new Bitmap(theImage);

    theBitmap.Save("newfileName.ico", System.Drawing.Imaging.ImageFormat.Icon);

     

    where I can type these lines to convert a ".jpg" file to ".ico" file or ".cur" file. or which software I can use

     

    Tuesday, January 29, 2008 8:54 AM
  • VB 2008 ... rejects the ico created with this method.  I tried various settings on the source PNG file, including 8-bit (256 color), no transparency and interlaced.  Even the pros at Microsoft use a third-party tool for creating icons.  I should too.
    Monday, September 07, 2009 4:31 PM
  • if it is an icon for your application, simply add an Icon file into your solution (Right click your project in the solution explorer > add > new item > Icon File

     

    Greetings,

    I'm using VC# 2010 Express.  When I right click the project in Solution Explorer, then Add, New Item I don't see a template listed for Icon files.  I have 23 choices, each of the Visual C# type.  Perhaps this is some 'selectable' functionality that I neglected to enable when installing VC#E, or is it a limitation of Express versus Pro?

    When I add an .ico as an "existing file" everything seems fine though a right click to open the ico results in launching MS Paint rather than the mini icon editor mentioned in the answer by ahmedilyas.

    Thanks for your help in advance.

    Tuesday, February 15, 2011 3:31 AM
  • hello ahmedilyas,how do you do. I have a simple question too.  Could you help me?  I am

    reading a book,Programming Windows by Charles Petzold.It is the 5th edition,and Petzold is a

    good author . The author  introduces Windows programming using VC++2008. But I have

    install VC++2010.  In Chapter 10, the author  prescribed how to create our own Icon. I dont

    know how to create my own icon using VC++2010. you may know ,VC++2010 is different from

    VC++2008.I dont know how to create a .RC file,though I know how to create .h and .IOC files.

    And I dont knowwhere the Icon'sID is. Could you like to help me?

    By the way,would you like to tell me how to be an excellent programmer as you? here is my

    email address: zhouweisen1986@gmail.com     i really need your help.

    Monday, October 29, 2012 3:38 AM