C# Visual Studio,更改应用程序图标,如何?

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

Visual Studio, change app icon, how?

c#visual-studiocachingicons

提问by mr-euro

I am working on a first time C# project in Visual Studio 2005 and I am wondering if there is anything special that needs doing to change the application icon apart from changing the correct resource in the project properties.

我正在 Visual Studio 2005 中处理第一个 C# 项目,我想知道除了更改项目属性中的正确资源之外,是否需要做任何特殊的事情来更改应用程序图标。

I manage to view the new icon displayed in Explorer, but the icon in the application, the tray, and the task bar stays as the old icon.

我设法查看资源管理器中显示的新图标,但应用程序、托盘和任务栏中的图标仍为旧图标。

I am wondering if this has anything to do with Windows Vista perhaps caching the applications icon and from then on not really refreshing it. The same happens in Explorer if you have thumbnails turned on.

我想知道这是否与 Windows Vista 可能缓存应用程序图标有关,然后从那时起并没有真正刷新它。如果您打开了缩略图,那么在 Explorer 中也会发生同样的情况。

If it does indeed cache the icon, what can I do to update/delete the cache, and also what is it based on (GUID perhaps? Not file name though as I changed that and still the same).

如果它确实缓存了图标,我可以做什么来更新/删除缓存,以及它基于什么(GUID 也许?不是文件名,虽然我改变了它,但仍然相同)。

Thanks

谢谢

采纳答案by dtb

Have you tried setting a Form.Icon(Winforms) or Window.Icon(WPF)?

您是否尝试过设置Form.Icon(Winforms) 或Window.Icon(WPF)?

回答by Kris Erickson

The Icon in tray, and the task bar is based on the Form or Window Icon. The application Icon (the one you see in explorer) is set in the properties.

托盘中的图标和任务栏基于窗体或窗口图标。应用程序图标(您在资源管理器中看到的图标)在属性中设置。

回答by Asad

It has probably nothing to do with Vista. Following shots shows a Windows Form Apploication runnig on Vista. You may have tried same template but using .Net Framwork 2.0. I am not sure but i think .Net Framework 3.0 was not available with VS 2005. You need to set the Forms Icon property.

它可能与 Vista 无关。下图显示了在 Vista 上运行的 Windows 窗体应用程序。您可能尝试过相同的模板,但使用的是 .Net Framwork 2.0。我不确定,但我认为 .Net Framework 3.0 不适用于 VS 2005。您需要设置 Forms Icon 属性。

回答by Bitterblue

Additionaltray icon from resources. Put an appropriate image into the resources and name it icon.

来自资源的附加托盘图标。将适当的图像放入资源中并将其命名为icon

NotifyIcon tray = new NotifyIcon();
tray.Icon = Icon.FromHandle(WindowsApplication1.Properties.Resources.icon.GetHicon());
tray.Visible = true;

回答by Trident

I had the exact same problem when I wanted to create an icon for my WinForms program. The following solution worked for me:

当我想为我的 WinForms 程序创建一个图标时,我遇到了完全相同的问题。以下解决方案对我有用:

Start creating an icon in i.e. Paint or Photoshop. Make the size preferably 256x256 and 24 bit color. If you use 32 bit color, you won't be able to make the background transparent. Save your image as .png.

开始在 ie Paint 或 Photoshop 中创建图标。使大小最好为 256x256 和 24 位颜色。如果您使用 32 位颜色,您将无法使背景透明。将您的图像另存为 .png。

Use your favourite internet browser and enter the page http://iconverticons.com/online/

使用您喜欢的互联网浏览器并进入页面http://iconverticons.com/online/

This page converts your .png into an .ico-file. Since you had an 256x256 input file, the web application is able to create an .ico-file with sizes from 256, 128, 64, 32, 24 and 16 squared.

此页面将您的 .png 转换为 .ico 文件。由于您有一个 256x256 的输入文件,因此 Web 应用程序能够创建大小为 256、128、64、32、24 和 16 平方的 .ico 文件。

This icon can then be added to your project by right-clicking your projects name in solution explorer -> Properties -> Application. Under the Resources-field, choose Icon and manifest, and press the three dotted button to the right for the icon-combo box. Browse to your icon-file and choose it.

然后可以通过在解决方案资源管理器 -> 属性 -> 应用程序中右键单击您的项目名称,将此图标添加到您的项目中。在资源字段下,选择图标和清单,然后按图标组合框右侧的三个虚线按钮。浏览到您的图标文件并选择它。

This will add the icon to your project as you can see when using windows explorer. Note that you have to copy the .exe file from your bin-directory into another directory in order to see the change of icons. This is because the thumbnail icons are not refreshed so easily.

这会将图标添加到您的项目中,正如您在使用 Windows 资源管理器时所看到的那样。请注意,您必须将 .exe 文件从 bin 目录复制到另一个目录中才能看到图标的变化。这是因为缩略图图标没有那么容易刷新。

This will, however, not add the icon to your task bar. In order to do that, go to your Form design window, that is where you can change the graphical appearance of your program. Go to properties and choose "Form1" in the combo box. There you will find an option called Icon. By browsing this property to your .ico-file, you can add the icon file to your program and it will appear on the task bar as well.

但是,这不会将图标添加到您的任务栏。为此,请转到您的表单设计窗口,您可以在该窗口更改程序的图形外观。转到属性并在组合框中选择“Form1”。在那里您会找到一个名为 Icon 的选项。通过浏览此属性到您的 .ico 文件,您可以将图标文件添加到您的程序中,它也会出现在任务栏上。

I hope this works for all of you who wants to add an icon to your project. I will add some descriptive images once I get enough rep.points to enable that :-|

我希望这适用于所有想要为您的项目添加图标的人。一旦获得足够的代表点数以启用该功能,我将添加一些描述性图像:-|

回答by iChal

I've just suffered from the same problem, 8 years on. It does appear that Windows (7) or Visual Studio (2017) is caching the icon. The only way I can find to clear this cache is with a power cycle.

我刚刚遇到同样的问题,8 年过去了。似乎 Windows (7) 或 Visual Studio (2017) 正在缓存该图标。我能找到清除此缓存的唯一方法是重启电源。