how to change the image in the resource folder

强颜欢笑 提交于 2020-01-06 07:47:05

问题


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);           
                }

回答1:


this is correct:

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

this is wrong:

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


来源:https://stackoverflow.com/questions/14481330/how-to-change-the-image-in-the-resource-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!