简体   繁体   English

Windows 表单图标未显示在任务栏中 C#

[英]Windows Form Icon not showing in Taskbar C#

I am adding an Icon to the Form i have created.我正在向我创建的表单添加一个图标。 When i run the program through VS2012 the icon shows up on the taskbar.当我通过 VS2012 运行程序时,图标显示在任务栏上。 But after publishing the project and installing it, the icon shows up in the Form border, but not in the taskbar.但是在发布项目并安装它之后,该图标显示在窗体边框中,但没有出现在任务栏中。 What am i doing wrong here?我在这里做错了什么?

I have tried resizing the icon.我试过调整图标大小。

您是否转到项目的属性并在“应用程序”选项卡中设置了一个图标(这当然应该与主窗口使用的图标相同,以避免混淆)?

你有没有去表格的属性和检查线:显示图标=“真”?

A dialog/form icon does not appear on taskbar until it receives proper keyboard focus. 在获得正确的键盘焦点之前,对话框/表单图标不会出现在任务栏上。 I am not quite sure what is the "proper" focus, but neither those who made windows were.This problem usaualy comes with missing of the first form activate event(oh yea it happends on regular basis). 我不太确定什么是“正确的”焦点,但是那些制造窗户的人都没有。这个问题通常缺少第一次形式激活事件(哦,是的,它定期发生)。 This may happen when you hide all the forms (in windows application) and then show the next form. 当您隐藏所有表单(在Windows应用程序中)然后显示下一个表单时,可能会发生这种情况。

So this does not work: 所以这不起作用:

newForm.Show () ;
currentForm.Hide () ; //The newForm does not have the proper focus yet

// actualy in this moment (I think) your application loose focus beacuse there is no application window.


This may do the trick: 这可能会成功:

newForm.Shown += newForm_Shown ;
newForm.Show () ;
void newForm_Shown ( object sender , EventArgs e )
{
    currentForm.Hide () ;
}

Whenever you can, you should show the next form before you hide previous form, and then hide the current form during shown/activate event of the new form. 只要可以,您应该在隐藏上一个表单之前显示下一个表单,然后在新表单的显示/激活事件期间隐藏当前表单。 Additional workournd that I know is to do some delayed form activation. 我知道的额外工作是做一些延迟形式激活。 You could try something like BeginInvoke on some form activation method, but this is generaly bad idea. 你可以在某种形式激活方法上尝试类似BeginInvoke的东西,但这通常是个坏主意。

Go to Properties->Application->Icon and manifest转到属性-> 应用程序-> 图标和清单

在此处输入图片说明

您也可以尝试在“ notifyIcon properties> Icon ”区域中添加图标。

不适合我这个解决方案转到属性->应用程序->图标和清单在这里输入图像描述

I came up with a fix for a similar issue.我想出了一个解决类似问题的方法。

Every time I ran my program (in debug or release mode) from Visual Studio 2022, the taskbar displayed the standard generic icon.每次我从 Visual Studio 2022 运行我的程序(在调试发布模式下)时,任务栏都会显示标准的通用图标。

在此处输入图像描述

But when I looked at the program using Windows Explorer, the executable was getting built with the correct icon.但是当我使用 Windows Explorer 查看程序时,可执行文件是用正确的图标构建的。

在此处输入图像描述

My Fix我的修复

  • I right clicked the executable in windows explorer, and selected " Pin To Taskbar ".我在 windows 资源管理器中右键单击可执行文件,然后选择“固定到任务栏”。
  • I then ran the program again from VS 2022, and the taskbar displayed the correct ICON.然后我再次从 VS 2022 运行程序,任务栏显示了正确的 ICON。
  • After running it, I unpinned it from the taskbar.运行它后,我从任务栏中取消固定它。

在此处输入图像描述

After that, the correct icon appeared when running it from VS 2022.之后,从 VS 2022 运行它时会出现正确的图标。

FYI: I had to perform this step for the executable in release and debug folders.仅供参考:我必须为发布调试文件夹中的可执行文件执行此步骤。

My Setup:我的设置:

  • OS: Windows 11 Pro操作系统: Windows 11 Pro
  • IDE: Visual Studio 2022 IDE: Visual Studio 2022
  • Project: C# Windows Forms App项目: C# Windows Forms App
  • An ICO file set in Project-Properties->Application->[Win32 Resource]->Icon在 Project-Properties->Application->[Win32 Resource]->Icon 中设置的 ICO 文件
  • A PNG file 128x128 resolution set in Project-Properties->Package->General->Icon在 Project-Properties->Package->General->Icon 中设置的 PNG 文件 128x128 分辨率
  • 在此处输入图像描述

What was happening in my case was that the taskbar icon was the form icon rather than the application icon, so you should check your form icon.在我的情况下发生的事情是任务栏图标是表单图标而不是应用程序图标,因此您应该检查您的表单图标。

I had a similar problem, when i set TopMost = false the app appears in the taskbar.我遇到了类似的问题,当我设置TopMost = false时,应用程序出现在任务栏中。

The Form and application icons were set in my project to an icon, but form "Show Icon" was hidden, and taskbar Icon was the blank rectangle.表单和应用程序图标在我的项目中设置为图标,但隐藏了表单“显示图标”,任务栏图标是空白矩形。

Showing Icon on form both showed it on the form, AND updated the icon in the taskbar.在表单上显示图标既显示在表单上,又更新了任务栏中的图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM