Question

Now, i developing a WinForms application. I need to create a custom control. My custom control uses a pictures. I don't want store these pictures in project resources file.

global::Wrigley_Data_Mart_Manager_2.Properties.Resources.previous_16x16;

I want to store pictures in resources file of custom control. But it's very uncomfortable. (designer always delete pictures from there). Where i can store image for my custom control? I want to my custom control was self-sufficient and that it can be used in other projects.

Was it helpful?

Solution

If you don't want to use a Resource (resx) then you could always include the image file within the project as an embedded resource.

You would create a folder to hold the image(s), and invoke "Add Existing", adding the images you'd like to embed into the project. Then in the Properties window for each file, for the "Build Action" selection, highlight the "Embedded Resource" option.

To access that file, you'd call Assembly.GetManifestResourceStream(string) with the full namespace of the project + the folder path within the project:

For Example, with Project Name: "MyCompany.MyTestProject" and you store the image(s) in the "Images" folder as "Images/image1.gif",

The namespace would then be:

Assembly.GetManifestResourceStream("MyCompany.MyTestProject.Images.image1.gif")

OTHER TIPS

An alternative could be converting them to byte arrays and storing them as BLOBs in your database.

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
     MemoryStream ms = new MemoryStream();
     imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
     return  ms.ToArray();
}

Then convert them back:

public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top