C# - 更改任务栏的图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15246520/
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
C# - Changing the icon of the taskbar
提问by loomie
I want to change the icon on the taskbar of my software, so I changed the project settings. This path was suggested by Visual Studio itself
我想更改软件任务栏上的图标,所以我更改了项目设置。这个路径是由 Visual Studio 本身建议的
But my taskbar still shows the same icon as before (the standard one) - In my Explorer the .exe has the correct icon, it just won't change in the taskbar.
但是我的任务栏仍然显示与以前相同的图标(标准图标) - 在我的资源管理器中,.exe 具有正确的图标,它不会在任务栏中更改。
I also tried to end explorer.exe and restart the task, but this didn't help at all. I also tried to set the resolution on 16x16 and 32x32 but both didn't work.
我还尝试结束 explorer.exe 并重新启动任务,但这根本没有帮助。我还尝试将分辨率设置为 16x16 和 32x32,但都不起作用。
采纳答案by Joey
You need to give your form that icon as well. The application icon is the one that is embedded in the application and displayed in Explorer or on shortcuts. Each form can have its own icon, though.
您还需要为您的表单提供该图标。应用程序图标是嵌入在应用程序中并显示在资源管理器或快捷方式上的图标。不过,每个表单都可以有自己的图标。
回答by Smaug
Set the Form.Icon
Property through code also consider the below suggestion from MSDN
Form.Icon
通过代码设置属性还考虑以下建议MSDN
A form's icon designates the picture that represents the form in the taskbar as well as the icon that is displayed for the control box of the form.
This property will have no effect if FormBorderStyle
is set to FixedDialog
. In that case, the form will not display an icon.
窗体的图标指定在任务栏中代表窗体的图片以及为窗体的控制框显示的图标。如果FormBorderStyle
设置为 ,则此属性将无效FixedDialog
。在这种情况下,表单将不会显示图标。
回答by Amicable
I've noticed a couple of things with Windows 7 and Windows 8. The Windows Taskbar icon is taken from the programs Shortcut's icon, not the applications icon.
我注意到 Windows 7 和 Windows 8 的一些事情。Windows 任务栏图标取自程序快捷方式的图标,而不是应用程序图标。
If you assign your application an Icon through Visual Studio it will set an icon that appears in the form as well as in the notification area. However the taskbar icon and any shortcut's you create will not take the icon from the application, as they used to, instead they are created with the default shortcut icon.
如果您通过 Visual Studio 为您的应用程序分配一个图标,它将设置一个显示在表单和通知区域中的图标。但是,任务栏图标和您创建的任何快捷方式不会像过去那样从应用程序中获取图标,而是使用默认快捷方式图标创建。
So I found that I had to set up the Shortcut icon's (that lives in the Start Menu) as part of my installer for the application.
所以我发现我必须将快捷方式图标(位于开始菜单中)设置为应用程序安装程序的一部分。
I don't have to do this for Windows XP.
我不必为 Windows XP 执行此操作。
回答by Nicolas Tyler
The icon set in the project properties is the icon of the executable and not the icon in the taskbar, the icon in the taskbar is the icon from the current form.
项目属性中设置的图标是可执行文件的图标而不是任务栏中的图标,任务栏中的图标是当前表单中的图标。
If you have multiple forms with the same icon and you set the icon of a form using the GUI then it will add multiple instances of the icon into the compiled executable file, this will lead to a larger compiled executable.
如果您有多个具有相同图标的表单,并且您使用 GUI 设置表单的图标,那么它会将图标的多个实例添加到编译后的可执行文件中,这将导致编译后的可执行文件更大。
So you should put this Icon = Properties.Resources.icon;
in the constructor of each form to set the icon of the form.
所以你应该把它Icon = Properties.Resources.icon;
放在每个表单的构造函数中来设置表单的图标。
As for the icon size, im not sure what the max size is but i use 128x128 icon files.
至于图标大小,我不确定最大大小是多少,但我使用 128x128 图标文件。
回答by Ali Reza
1 - Add a file (e.g. Address_Book.ico) to Resources section
1 - 将文件(例如 Address_Book.ico)添加到资源部分
2 - Add follow lines in your code
2 - 在您的代码中添加以下行
public Form1()
{
....
this.Icon = Properties.Resources.Address_Book;
}
3 - It Works.
3 - 它有效。
回答by yadavr
You will require to use notifyicon component from toolbox. Please follow the instructions as given below.
您将需要使用工具箱中的 notifyicon 组件。请按照以下说明进行操作。