Reputation: 180
Currently i have a program that uses a file (picture) from my PC. I found out i can load my picture into the program DataSources
but this won't help me solving my problem. When I replace the program or transfer it to another PC and run, it crashes because of the second line:
InitializeComponent();
Animation = new Bitmap(@"C:\Users\User\Documents\Visual Studio 2015\Projects\CourseWork\CourseWork\Properties\DataSources\Selection-Sort-Animation (1).gif");
I wonder how to set the path (@"")
properly or do something else so my program can find and load a picture on any machine.
Upvotes: 1
Views: 55
Reputation: 125197
You can put the image in a Resources.resx
file.
When you create a Windows Forms Application, if you look in solution explorer, you will see a Resources.resx
file exists in the Properties
folder. you can use this file (or add another .resx
file) to embed resources in your application to do so:
Using Resource Designer:
Resoures.resx
designer.Resources.resx
with a name. Accessing Resources:
You can access each resource simply with its name, for example:
this.PictureBox1.Image= Properties.Resources.Loading;
Upvotes: 1