C# 在 Visual Studio 中向项目添加图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15474366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 16:57:16  来源:igfitidea点击:

Adding an image to a project in Visual Studio

c#visual-studio

提问by DextrousDave

I added a folder to my project by right clicking on the project and adding a new folder. Now I added the image to the folder (using copy paste in Windows File Explorer), but the solution explorer is not showing my added image. I did refresh the solution as well.

我通过右键单击项目并添加一个新文件夹向我的项目添加了一个文件夹。现在我将图像添加到文件夹中(使用 Windows 文件资源管理器中的复制粘贴),但解决方案资源管理器没有显示我添加的图像。我也刷新了解决方案。

Also, in that folder, there is no option of adding an image, only Visual Studio files (new items etc)..

此外,在该文件夹中,没有添加图像的选项,只有 Visual Studio 文件(新项目等)。

Why isn't Solution Explorer showing my image?

为什么解决方案资源管理器不显示我的图像?

采纳答案by DerApe

  • You just need to have an existing file, open the context menu on your folder , and then choose Add=> Existing item...

    enter image description here

  • If you have the file already placed within your project structure, but it is not yet included, you can do so by making them visible in the solution explorer

    enter image description here

  • 您只需要拥有一个现有文件,打开文件夹上的上下文菜单,然后选择Add=>Existing item...

    在此处输入图片说明

  • 如果您的项目结构中已经放置了该文件,但尚未包含该文件,您可以通过在解决方案资源管理器中将它们设置为可见来实现

    在此处输入图片说明

and then include them via the file context menu enter image description here

然后通过文件上下文菜单包含它们 在此处输入图片说明

回答by Mike Perrenoud

Click on the Project in Visual Studio and then click on the button titled "Show all files" on the Solution Explorer toolbar. That will show files that aren't in the project. Now you'll see that image, right click in it, and select "Include in project" and that will add the image to the project!

单击 Visual Studio 中的项目,然后单击解决方案资源管理器工具栏上标题为“显示所有文件”的按钮。这将显示不在项目中的文件。现在您将看到该图像,右键单击它,然后选择“包含在项目中”,这会将图像添加到项目中!

回答by Alexander Tsvetkov

You need to turn on Show All Filesoption on solution pane toolbar and include this file manually.

您需要打开Show All Files解决方案窗格工具栏上的选项并手动包含此文件。

回答by jkhosla

If you're having an issue where the Resources added are images and are not getting copied to your build folder on compiling. You need to change the "Build Action" to None from Resource ( which is the default) and change the Copy to "If Newer" or "Always" as shown below :

如果您遇到添加的资源是图像并且在编译时没有复制到构建文件夹的问题。您需要将“构建操作”从资源(这是默认值)更改为“无”,并将“复制”更改为“如果较新”或“始终”,如下所示:

enter image description here

在此处输入图片说明