这是一个外观问题,但我的应用程序在控制面板上有一个默认图标。许多其他应用程序都有自定义图标。
我的应用程序确实有菜单和任务栏的自定义图标。
如何使用 Visual Studio 2015 或更高版本更改控制面板上显示的图标?
更新:
Visual Studio 创建安装程序的方式发生了变化。我不确定它是什么时候发生的,但 2015 年肯定没有“部署项目”。Google 上的大多数点击都建议转到 VS 2015 应用程序下不存在的部署项目属性。
这就是为什么我包含了 visual-studio-2015 标签的原因。抱歉,没有在原始问题中提到这一点。这将是很好的信息。
可以使用注册表,但提到的注册表路径 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 不存在。让应用程序一直在注册表中检查它自己的图标确实听起来很笨拙。对我来说,这听起来像是一个安装程序功能。
Microsoft Developer Network 上的一篇文章提供了答案。它还修改注册表。我通过删除应用程序名称和图标文件的硬编码值来增强它。
// These references are needed:
// using System.Reflection;
// using System.Deployment.Application;
// using System.IO;
// using Microsoft.Win32;
private static void SetAddRemoveProgramsIcon(string iconName)
{
// only run if deployed
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
try
{
string assemblyTitle="";
object[] titleAttributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), true);
if (titleAttributes.Length > 0 && titleAttributes[0] is AssemblyTitleAttribute)
{
assemblyTitle = (titleAttributes[0] as AssemblyTitleAttribute).Title;
}
string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, iconName);
if (!File.Exists(iconSourcePath))
{
return;
}
RegistryKey myUninstallKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
string[] mySubKeyNames = myUninstallKey.GetSubKeyNames();
for (int i = 0; i < mySubKeyNames.Length; i++)
{
RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true);
object myValue = myKey.GetValue("DisplayName");
if (myValue != null && myValue.ToString() == assemblyTitle)
{
myKey.SetValue("DisplayIcon", iconSourcePath);
break;
}
}
}
catch (Exception) { }
}
return;
}
Robin Shahan的原始文章在这里:RobinDotNet
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句