Live Chat Icon For mobile
Live Chat Icon

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

Platform: WinForms| Category: Resources

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();
	}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.