0

I am a student studying c# and working on winform.

I have a winform which have a splashForm which loads its background image from the resources folder. and after the splash screen in the mainForm there is a option to change the splash screen background using openFileDialog.

I want to replace the image(splashimage.jpg) from resource folder image base on the selected. And I want to copy the image from user selected to the resource folder and remove the previous image and rename the image of the newly copied image to the (splashimage.jpg).

I have this code but it does not work for the replacing the image from the resource folder base on the selected image using openFileDialog.

    var FD = new System.Windows.Forms.OpenFileDialog();
                FD.Filter = "jpeg files|*.jpg";
                if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                   System.IO.File.Copy(FD.FileName,Application.StartupPath
+ "\\" + splashimage.jpg", true);           
                }
spajce
  • 7,044
  • 5
  • 29
  • 44
shariq_khan
  • 671
  • 4
  • 16
  • 33
  • What part of it deosnt work? –  Jan 23 '13 at 13:50
  • @RhysW the system.IO.Copy...... the error which is "Could not find a part of the path 'Application.StartupPath\aquib1.jpg'." – shariq_khan Jan 23 '13 at 13:51
  • Thats because youve types in "Application.StartupPath" as plain text rather than as the actual variable –  Jan 23 '13 at 13:53
  • @RhysW it is still not copying the image to the resource location.. – shariq_khan Jan 23 '13 at 13:57
  • Ok but is it erroring or breaking still or just not copying? –  Jan 23 '13 at 14:03
  • Also worth noting, Application.StartupPath is the location of the program executing the code not the location of the sourcecode itself, to find out where it is putting it do a quick var path = Application.StartupPath; Put a breakpoint there, then hover over it and see just where it is trying to put the file –  Jan 23 '13 at 14:07
  • in short do you want to change the background of the `Form` using `OpenFileDialog`? – spajce Jan 24 '13 at 19:26
  • check http://stackoverflow.com/questions/6398119/how-to-edit-a-resource-file – spajce Jan 24 '13 at 21:59

1 Answers1

0

this is correct:

this.BackgroundImage = Image.FromFile(Application.StartupPath
+ "\\" + splashimage.jpg")

this is wrong:

this.BackgroundImage = Image.FromFile("Application.StartupPath"
+ "\\" + splashimage.jpg")
alont
  • 263
  • 2
  • 3
  • 12
  • sir this was not my question. the background image which you are setting the form is not active. i have a splash form when it is closed i want to change the background image of that as my splash form takes the image from the system resources folder. i want that a open file dialog is setting the image which the user selects and copys the image and renaming it to the splashimage.jpg as my background image name is splashimage.jpg. now you understood – shariq_khan Jan 23 '13 at 16:25
  • @shariq_khan this is the error message right? "Could not find a part of the path 'Application.StartupPath\aquib1.jpg" – alont Jan 24 '13 at 04:49
  • @shariq_khan - Can you please post the code how your splash form takes the image from the system resources folder. – alont Jan 24 '13 at 04:50
  • sir i have set the property of the background image to the resources folder of the app. which contains all the image. have you understood? – shariq_khan Jan 24 '13 at 18:19