C# 更改默认图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10223477/
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-09 12:57:18  来源:igfitidea点击:

Change default icon

c#.netwinformsicons

提问by jorne

I'm trying to change the application icon from default to something else. So what I did, is I made an icon and saved it. Then I went to the application tab in the property of my project and changed the icon. There he shows the icon like I made it, but when I run my project it shows a gray icon instead of showing my icon.

我正在尝试将应用程序图标从默认更改为其他图标。所以我所做的是,我制作了一个图标并保存了它。然后我转到项目属性中的应用程序选项卡并更改图标。他在那里显示了我制作的图标,但是当我运行我的项目时,它显示一个灰色图标而不是我的图标。

What i'm doing wrong here?

我在这里做错了什么?

采纳答案by Default

Run it notthrough Visual Studio - then the icon should look just fine.

通过 Visual Studio运行它- 那么图标应该看起来很好。

I believe it is because when you debug, Visual Studio runs <yourapp>.vshost.exeand not your application. The .vshost.exe file doesn't use your icon.

我相信这是因为当您调试时,运行的是 Visual Studio<yourapp>.vshost.exe而不是您的应用程序。.vshost.exe 文件不使用您的图标。

Ultimately, what you have done is correct.

最终,你所做的是正确的。

  1. Go to the Project properties
  2. under Application tab change the default icon to your own
  3. Build the project
  4. Locate the .exe file in your favorite file explorer.
  1. 转到项目属性
  2. 在应用程序选项卡下将默认图标更改为您自己的
  3. 构建项目
  4. 在您喜欢的文件资源管理器中找到 .exe 文件。

There, the icon should look fine. If you run it by clicking that .exe the icon should be correct in the application as well.

在那里,图标应该看起来不错。如果您通过单击该 .exe 来运行它,则应用程序中的图标也应该是正确的。

回答by Likurg

Go to form's properties, ICON ... Choose an icon you want.

转到表单的属性,图标 ... 选择您想要的图标。

EDIT:try this

编辑:试试这个

  1. Edit App.Ico to make it look like you want.
  2. In the property pane for your form, set the Icon property to your project's App.Ico file.
  3. Rebuild solution.
  1. 编辑 App.Ico 使其看起来像您想要的。
  2. 在窗体的属性窗格中,将 Icon 属性设置为项目的 App.Ico 文件。
  3. 重建解决方案。

And read this one icons

并阅读这个图标

回答by AlphaMale

The Icon property for a project specifies the icon file (.ico) that will be displayed for the compiled application in Windows Explorer and in the Windows taskbar.

The Icon property can be accessed in the Application pane of the Project Designer; it contains a list of icons that have been added to a project either as resources or as content files.

To specify an application icon

  1. With a project selected in Solution Explorer, on the Project menu click Properties.
  2. Select the Application pane.
  3. Select an icon (.ico) file from the Icon drop-down list.

To specify an application icon and add it to your project

  1. With a project selected in Solution Explorer, on the Project menu, click Properties.
  2. Select the Application pane.
  3. Select Browsefrom the Icon drop-down list and browse to the location of the icon file that you want.

The icon file is added to your project as a content file and can be seen on top left corner.

项目的 Icon 属性指定将在 Windows 资源管理器和 Windows 任务栏中为编译的应用程序显示的图标文件 (.ico)。

可以在项目设计器的应用程序窗格中访问图标属性;它包含已作为资源或内容文件添加到项目中的图标列表。

指定应用程序图标

  1. 在解决方案资源管理器中选择一个项目后,在“项目”菜单上单击“属性”。
  2. 选择应用程序窗格。
  3. 从图标下拉列表中选择一个图标 (.ico) 文件。

指定应用程序图标并将其添加到您的项目中

  1. 在解决方案资源管理器中选择一个项目后,在“项目”菜单上,单击“属性”。
  2. 选择应用程序窗格。
  3. 从图标下拉列表中选择浏览并浏览到所需图标文件的位置。

图标文件作为内容文件添加到您的项目中,可以在左上角看到。

And if you want to show separate icons for every form you have to go to each form's properties, select icon attribute and browse for an icon you want.

如果您想为每个表单显示单独的图标,您必须转到每个表单的属性,选择图标属性并浏览您想要的图标。

Here's MSDN linkfor the same purpose...

这是出于相同目的的MSDN 链接...

Hope this helps.

希望这可以帮助。

回答by MarcoM

you should put your icon on the project folder, before build it

在构建它之前,您应该将图标放在项目文件夹上

回答by riffnl

Your application icon shows in the taskbar. The icon on the topleft (window) is the form-icon. Go to your form and fill the property "icon" with the same icon; problem solved. You don't need to put the icon in the outputfolder (that's just for setups).

您的应用程序图标显示在任务栏中。左上角(窗口)的图标是表单图标。转到您的表单并使用相同的图标填写属性“图标”;问题解决了。您不需要将图标放在输出文件夹中(仅用于设置)。

回答by Guy

If your designated icon shows when you run the EXE but not when you run it from Visual Studio, then, for a WPF project add the following at the top of your XAML: Icon="Images\MyIcon.ico". Put this just where you have the Title, and xmlns definitions. (Assuming you have an Images folder in your project, and that you added MyIcon.ico there).

如果您指定的图标在运行 EXE 时显示,但在从 Visual Studio 运行时不显示,则对于 WPF 项目,在 XAML 顶部添加以下内容:Icon="Images\MyIcon.ico"。把它放在你有标题和 xmlns 定义的地方。(假设您的项目中有一个 Images 文件夹,并且您在那里添加了 MyIcon.ico)。

回答by Scott

I had the same problem. I followed the steps to change the icon but it always installed the default icon.

我有同样的问题。我按照步骤更改了图标,但它始终安装了默认图标。

FIX: After I did the above, I rebuilt the solution by going to build on the Visual Studio menu bar and clicking on 'rebuild solution' and it worked!

修复:完成上述操作后,我通过在 Visual Studio 菜单栏上构建并单击“重建解决方案”来重建解决方案,并且成功了!

回答by Dan

If you are using Formsyou can use the icon setting in the properties pane. To do this select the form and scroll down in the properties pane till you see the icon setting. When you open the application it will have the icon wherever you have it in your application and in the task bar

如果您正在使用,Forms您可以使用属性窗格中的图标设置。为此,请选择表单并在属性窗格中向下滚动,直到看到图标设置。当您打开应用程序时,它会在您的应用程序和任务栏中的任何位置显示该图标

Icon settings

图标设置

回答by ??????? ????????

Go to the Project propertiesBuild the project Locate the .exe file in your favorite file explorer.

转到项目属性构建项目 在您喜欢的文件资源管理器中找到 .exe 文件。