none
How to "embed" an Image in my WinForms Application and call it from inside the App

    Question

  • Hi,

    i need to change dynamically from my Code Behind the Images on Buttons or Menu Elements. For this case i would like to store the different Icons/Images in my Application and use them at Runtime from within the Code Behind and assign them to different Buttons, Menu Elements etc.

    But I dont know where to start. Could someone give me a hint? 


    Best regards,
    Yavuz B.

    My Sharepoint and Enterprise 2.0 Blog http://www.starcoder.net
    Microsoft Sharepoint Resources & Blogs List
    Monday, November 01, 2010 6:33 PM

Answers

  • There are many ways to do this

    1) Imagelist control : Add your icons/images to imagelist and you can access them at runtime

    2) Managed Resources : Right click your project name, and select properties from menu, on properties, select resources tab and add your images or icons as existing item.Now you can access the icon or image from resources as
       Dim img as Bitmap = My.Resources.YourResourcesNameWithoutExtension
       Dim Ic as Icon = My.Resources.YourResourcesNameWithoutExtension
    3) Embedded Resources : To add any file as an embedded resource in a windows forms application, add the file to the project with Project | Add Existing Item or right click your project name in solution explorer and click Add Existing item. Then select the file in the Solution Explorer, go to the Properties Window, and set its Build Action property to Embedded Resource. The file will be embedded within your compiled executable, when you build the project.

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Proposed as answer by Mr.Mubi Monday, November 01, 2010 7:12 PM
    • Unproposed as answer by [Yavuz B.] Monday, November 01, 2010 7:29 PM
    • Marked as answer by [Yavuz B.] Monday, November 01, 2010 7:29 PM
    Monday, November 01, 2010 7:05 PM

All replies

  • There are many ways to do this

    1) Imagelist control : Add your icons/images to imagelist and you can access them at runtime

    2) Managed Resources : Right click your project name, and select properties from menu, on properties, select resources tab and add your images or icons as existing item.Now you can access the icon or image from resources as
       Dim img as Bitmap = My.Resources.YourResourcesNameWithoutExtension
       Dim Ic as Icon = My.Resources.YourResourcesNameWithoutExtension
    3) Embedded Resources : To add any file as an embedded resource in a windows forms application, add the file to the project with Project | Add Existing Item or right click your project name in solution explorer and click Add Existing item. Then select the file in the Solution Explorer, go to the Properties Window, and set its Build Action property to Embedded Resource. The file will be embedded within your compiled executable, when you build the project.

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Proposed as answer by Mr.Mubi Monday, November 01, 2010 7:12 PM
    • Unproposed as answer by [Yavuz B.] Monday, November 01, 2010 7:29 PM
    • Marked as answer by [Yavuz B.] Monday, November 01, 2010 7:29 PM
    Monday, November 01, 2010 7:05 PM
  • Great Reply, thank you very much!
    Best regards,
    Yavuz B.

    My Sharepoint and Enterprise 2.0 Blog http://www.starcoder.net
    Microsoft Sharepoint Resources & Blogs List
    Monday, November 01, 2010 7:31 PM
  • Thanks from me as well, I have been struggling to keep my image file inside my simple .exe for DAYS, and this simple post was exactly what I needed.
    Sunday, November 14, 2010 11:33 PM