George Shepherd's Windows Forms FAQ
Questions and answers in this FAQ have been collected from newsgroup posts, various mailing lists and the employees of Syncfusion.

16.2 How do I load a BMP file that has been added to my solution as an embedded resource


If you add a BMP file to your solution using the File|Add Existing Item... Menu Item, then change the Build Action property of this BMP file to Embedded Resource, you can then access this resource with code similar to:

     
     // WindowsApplication6 corresponds to Default Namespace in your project settings.
     // subfolders should be the folder names if any, inside which the bmp is added. If the bmp was added to the top level, you don't have to specify anything here.
     string bmpName = "WindowsApplication6.subfolders.sync.bmp";
     System.IO.Stream strm = null;
     try
     {
          strm = this.GetType().Assembly.GetManifestResourceStream(bmpName);
          pictureBox1.Image = new Bitmap(strm);
          // Do the same for Icons
          // Icon icon1 = new Icon(strm);
     }
     catch(Exception e)
     {
          MessageBox.Show(e.Message);
     }
     finally
     {
          if(strm != null)
               strm.Close();
     }


Windows Forms-Resources

© 2001-2008 Copyright Syncfusion Inc. All rights reserved.  |  Privacy Policy  |  Contact  |  Sitemap