FileNotFound Exception for OnHover after FileOpen.ShowDialog

  • Thread starter Thread starter Stork via DotNetMonster.com
  • Start date Start date
S

Stork via DotNetMonster.com

Hi,

I have a program that has a row of buttons that use MouseEnter/MouseLeave to
change between two different colored images. I also have other images that I
pull from the filing system. Since I have several thousands pictures of
product, putting the images in an ImageList is out of the question as that
would make the EXE file insanely huge and eat up tons of resources.

My problem is I am trying to avoid having to type the full path of the images
(C:\Program Files\etc) so that no matter where a user installs the program,
and no matter the drive letter/name, it will work correctly. Everything works
fine until I open the Save or Open Dialog box, and then when an image is
pulled from the file system it throws up a 'File Not Found Exception'.


Code:
private void btnSave_Click(object sender, EventArgs e)
{
fileSave.ShowDialog();
}

private void btnSave_MouseEnter(object sender, EventArgs e)
{
btnSave.Image = System.Drawing.Image.FromFile(@"Images\Main\save-
oj.jpg");
}

private void btnSave_MouseLeave(object sender, EventArgs e)
{
btnSave.Image = System.Drawing.Image.FromFile(@"Images\Main\save-
blu.jpg");
}

Any idea on how I can get around this problem?
 
Stork,

You assume that the current working folder is the parent folder of Images.
It looks like this is not the case. Normally when the application starts the
working folder is the folder of the exe, but can be changed.

I suggest to use Application.StartupPath to get the folder of the executable
and then construct your path from there.
 
Works great, thanx!
Stork,

You assume that the current working folder is the parent folder of Images.
It looks like this is not the case. Normally when the application starts the
working folder is the folder of the exe, but can be changed.

I suggest to use Application.StartupPath to get the folder of the executable
and then construct your path from there.
[quoted text clipped - 36 lines]
Any idea on how I can get around this problem?
 
Back
Top