在资源管理器中设置应用程序图标?

28
我正在尝试为我创建的程序设置文件图标。当我运行程序时,可以在任务栏上显示图标。但是我无法在文件浏览器中显示它。 以下是来自资源管理器的示例截屏: Example 我已将图标嵌入到项目中,并使用以下方式将其设置为Windows图标:
Icon="Sample.ico"

谢谢


尝试在“发布”模式下编译您的代码。 - Hari Prasad
5个回答

37
您已经为您的应用程序选择了图标吗?(项目属性 > 应用程序选项卡 > 符号和清单 > 符号)

1
非常感谢。我不知道这是 Visual Studio 的一部分。 - Stephen White

12
以下示例演示如何设置窗口图标。
通过使用XAML,
<Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.MainWindow"
    Icon="WPFIcon1.ico">
</Window>

通过使用 C# 代码,

Uri iconUri = new Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);

通过使用VB,

Dim iconUri As New Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute)
Me.Icon = BitmapFrame.Create(iconUri)

欲了解更多信息,请参见此处


我认为这并没有真正回答问题。OP并没有询问窗口的角落图标。 - StayOnTarget

2

请确保你的.ico文件包含正确的尺寸,以便在资源管理器中显示适当的尺寸。

对于Windows,您需要以下尺寸:

256 x 256像素, 48 x 48像素, 32 x 32像素和 16 x 16像素。

所有都是32位(24位彩色,8位透明度)。


-1

-1

你必须在主窗口的窗口定义中包含 Icon="图标路径"

<Window 
//rest of code
Icon="Path to icon"></Window>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接