如何更改资源文件夹中的图像 [英] how to change the image in the resource folder

查看:94
本文介绍了如何更改资源文件夹中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名学习c#并从事winform工作的学生.

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

我有一个Winform,其中有一个splashForm,可从资源文件夹中加载其背景图像.在mainForm初始屏幕之后,有一个选项可以使用openFileDialog更改初始屏幕背景.

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.

我要根据所选内容替换 resource 文件夹 image 中的图像( splashimage.jpg ).我想将所选用户的图像复制到资源文件夹,并删除前一个图像,然后将新复制的图像的图像重命名为( splashimage.jpg ).

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).

我有这段代码,但是它对于使用openFileDialog基于所选图像替换 resource 文件夹中的图像不起作用.

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

推荐答案

这是正确的:

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

这是错误的:

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

这篇关于如何更改资源文件夹中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆