How to load my jpg file into pictureBox

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

Guest

I want to show a pic using pictureBox in my app.
I use the following code:
pictureBox1.Image=new Bitmap("MMS.jpg");

It works fine when running on my PC. But it fails when running my app
"client.exe" on my pocket pc.(MMS.jpg and client.exe are under the same
directory)

Any help would be greatly appreciated.
Thanks
 
Managed IOException
__Error::WinIOError+0x8a
FileStream::.ctor+0xee
FileStream::.ctor+0x16
Bitmap::.ctor+0xf
Login::InitializeComponent+0xe6
Login::.ctor+0xc
Login::.Main+0xa

Thank you:)
 
I'm surprised its an IOException and not a FileNotFound exception. You need
to specify the full file path:-
pictureBox1.Image=new Bitmap("\\Program Files\\MyApp\\MMS.jpg");
Where \\Program Files\\MyApp\\ is replaced with the path to your app. You
can use
string apppath =
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

To get the path in which your exe is located. then add your filename to this
pictureBox1.Image=new Bitmap(apppath + "\\MMS.jpg");

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Back
Top