Problem accessing file in PictureBox control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using VS 2003, i have dragged and dropped a picture box control to my smart
app form, and have selected the image using the properties dialog box. The
project builds fine, w/out errors. However, when i attempt to run the
application, i get the following error:

A first chance exception of type 'System.IO.FileNotFoundException' occurred
in mscorlib.dll. Additional information: FileNotFoundException.

My image file's build action property is set to Embedded. Anyone have ideas
as to what am i doing wrong?

Thanks,
 
The easiest way to setup a picturebox with an embedded image is within your
code, not using the designer. Remove the image property in the designer
properties window and then switch to the code for your form, add this or
equivalent to your form constructor after the call to InitializeComponent:-

PictureBox1.Image = new
Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Namespace.Filename"));

The name of your embedded resource will depend on whether it is in the root
of your project or in a subfolder, and whether you have a default namespace
set in the project settings. If you have problems determining the exact
resource name you can use ildasm in the .NET SDK to look inside your
compiled exe. Alternatively use:-
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
to return an array of strings with all the embedded resource names.

Peter
 
This is what i've been doing. However, for simple 'About us" forms, i had
thought that just using the designer would suffice. Thanks for the
clarification.
 
Back
Top