Click here to Skip to main content
12,954,203 members (52,898 online)
Rate this:
Please Sign up or sign in to vote.
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

var FD = new System.Windows.Forms.OpenFileDialog();
                FD.Filter = "jpeg files|*.jpg";
                if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ "\\" + splashimage.jpg", true);
Posted 23-Jan-13 5:30am
Updated 23-Jan-13 5:32am
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?
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?
jibesh 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
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.
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.
sariqkhan 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2017
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