Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i am a student studying c# and working on wnform. i have a winform which have a splash form which loads its background image from the resources folder. and after the splash screen and in the main software there is a setting from which i have a button so that the splash screen can be changed with the help of open file dialog. so i want that it should replace the image splashimage.jpg in the resource folder with the image the user selected. i want to copy the image the use 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 the image in the resource folder is not changing with the image which i have selected in the open file dialog i dont know why it is not working
 
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);
                }
Posted 23-Jan-13 6:30am
sariqkhan1.4K
Edited 23-Jan-13 6:32am
v2
Comments
Alan N at 23-Jan-13 11:44am
   
That code copies creates a file called splashimage.jpg in the application's base directory. Is that where the file is supposed to be?
sariqkhan at 24-Jan-13 13:23pm
   
i think so but it copies right. but the image in the resource folder is not replacing when this is completed.
Sergey Alexandrovich Kryukov at 23-Jan-13 15:18pm
   
First of all, why would you need to copy a file. You copy it, what's the use?
"Not working" is not informative. Did copy fail?
—SA
sariqkhan at 24-Jan-13 13:25pm
   
no sir the copy isnt failed. but in the resource folder there is an image which name is splash image.jpg i want to replace with that image with same name. but after this operation the image is not replacing
Sergey Alexandrovich Kryukov at 24-Jan-13 14:16pm
   
The, it sound to me that the problem does not exist. If you just copies something, why would you see it can be "replaced"? You also should use it somehow.
By the way, why on Earth would you like to replace such think as splash during runtime?
—SA
jibesh at 23-Jan-13 18:57pm
   
The above code works fine for me. I think the problem may the "splashimage.jpg" file is already in use by the splash form so it wont allow to replace the old splashimag.jpg. try disposing your splash.form and the image and then try the Copy operation you will be fine.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The possible reason could be the 'splashimage.jpg' loaded by the splash form is in use and hence you cannot replace it.
 
Check your splash form which loads the splashimage is disposed before you perform the copy operation. or atleast dispose the image file you loaded to the splash form.
  Permalink  
v2
Comments
sariqkhan at 24-Jan-13 13:23pm
   
how can it be disposed? can you help me to dispose so that i can replace the image. i have set the property of the splash form image to the image which is in the resource folder and i have provide this code but it doesnt replaced the image. i want to replace the image with the same name.
jibesh at 24-Jan-13 13:25pm
   
you can use the image.Dispose method to dispose the image. can you share the code how you use to display and hide/close splash form
jibesh at 24-Jan-13 13:40pm
   
one more question: from where you are loading the image.jpg file, from folder or was it embedded with the application?
sariqkhan at 26-Jan-13 11:35am
   
i am loading the image from the resource folder. i have set the property of the background image to the resource folder contain a image
jibesh at 26-Jan-13 19:21pm
   
Ok. so what are you trying here. Copy is working fine. means your file is replaced with the new image. can you explains the steps that you want to perform.
wait do you want to display the new image on the splash form when you replace with new image?
 
if your copy is success you need to set the image once again to the splash form because replacing a file doesnt replace the image that is already loaded in the form. so you need to force the form to use the updated image by setting it again.
 
try this.
sariqkhan at 28-Jan-13 3:53am
   
sir how can i automatically load that? i dont want to edit whole software for that as i am providing this funtionality to the user. and about copy. in the resource folder you are getting the new image with same name?? i a m not getting the new image in the resource folder. its the same image there which is older.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 337
1 DamithSL 310
2 OriginalGriff 220
3 Zoltán Zörgő 149
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 5,044
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100