Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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

C#
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
Updated 23-Jan-13 5:32am
v2
Comments
Alan N 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 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 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 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 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

1 solution

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.
 
Share this answer
 
v2
Comments
sariqkhan 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 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 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 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 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900