了解 C# 应用程序中的图标索引

发布于 2024-12-02 14:38:31 字数 459 浏览 5 评论 0原文

我有一个 C# 应用程序,需要为用户在使用该应用程序时可以保存和加载的项目文件定义一个图标。我知道如何设置注册表项,但我正在努力解决的是项目文件扩展名的 DefaultIcon 的图标索引。

我已将图标添加到资源文件中。我还将该图标添加到 Visual Studio 中的 Resources 文件夹中。然而,当我重新启动电脑时,索引 1 没有图标,索引 0 是应用程序图标。

我尝试将图标持久性设置为“嵌入.resx”。没有帮助。

我添加了一个名为 PublicIcons.resx 的新资源文件,将访问修饰符设置为“公共”并添加了图标。也没有帮助。

我尝试将图标直接添加到项目中并将构建操作设置为“嵌入式资源”。再次,没有帮助。

嘎啊!为什么如此简单的任务如此烦人?

如何将图标添加到 Visual Studio 中的 C# 项目,然后发现该图标的索引,以便将其用于文件类型?

谢谢,安迪

I have a C# application that needs to define an icon for the project files that the user can save and load when using the application. I know how to set up the registry entries but what I am struggling with is the icon index for the DefaultIcon for the project file extension.

I've added the icon to the Resources file. I've also added the icon to the Resources folder in Visual Studio. Yet when I reboot my PC an index of one has no icon and an index of zero is the application icon.

I tried setting the icon persistence to "Embedded in .resx". Didn't help.

I added a new resource file called PublicIcons.resx, set the access modifier to "Public" and added the icon. Didn't help either.

I tried adding the icon directly to the project and setting the build action to "Embedded Resource". Again, didn't help.

Gaaaa! Why is such a simple task so annoying?

How do I add an icon to a C# project in Visual Studio and then discover the index of that icon so it can be used for a file type?

thanks, Andy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分分钟 2024-12-09 14:38:31

我已经解决了。今天我花了几个小时试图完成这个简单的任务 - 阅读有关安装和部署项目、ClickOnce、清单文件、fileAssociation 标记、Visual Studio 2010 资源文件等等的内容。但这里是如何在两分钟内解决问题:

在 VS2010 解决方案中添加一个新的空 C++ 项目:添加 ->新项目->视觉 C++ ->空项目。我称之为“资源库”。

右键单击资源文件文件夹,然后选择添加 ->资源...并选择图标。

右键单击“源文件”文件夹,然后选择“添加”->“添加”新项目... -> C++ 文件。我调用了我的 main.cpp。输入:

int main(void) { return 0; }

然后使用适当的注册表项和您选择的安装程序编译您的文件并将其与 ResourceLibrary.exe 中的图标索引零关联!

简单有效。

I've solved it. I have spent hours today trying to accomplish this simple task - reading about Setup and Deployment projects, ClickOnce, manifest files, fileAssociation tags, Visual Studio 2010 resource files, on and on and on. But here is how to solve the problem in literally two minutes:

In your VS2010 solution add a new empty C++ project: Add -> New Project -> Visual C++ -> Empty Project. I called my "ResourceLibrary".

Right click on the Resource Files folder then choose Add -> Resource... and select the icon.

Right click on the Source Files folder then choose Add -> New Item... -> C++ File. I called my main.cpp. Enter:

int main(void) { return 0; }

Then compile and associate your file with icon index zero in ResourceLibrary.exe using the appropriate registry entry and the installer program of your choice!

Simple and effective.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文