To embed the files, open the Project menu and select Add Existing Item. Select the files to add them to the Solution Explorer. In the file selection dialog, set the "Files of type" dropdown to All Files so you can see the files.
Click on the files in Solution Explorer and open the Properties window. Select the file's Build Action property, click the dropdown arrow on the right, and select Embedded Resource. Now when you compile the program, the files are embedded as resources in the application.
To load the files at run time, the program gets its assembly. Resource files stored in the application in this manner have names of the form assembly_name.file_name so the program uses the assmebly's GetName().Name.ToString() method to get the assembly's name.
To get an embedded file, the program uses the assembly's GetManifestResourceStream method to get a stream attached to the file's data. To read a bitmap file, the program makes a Bitmap passing the stream to the Bitmap's constructor.
To read a text file, the program makes a StreamReader, passing the stream to its constructor.
|