Adding multiple Icons (Win32-Resource) to .NET-Application
Windows doesn't know anything about managed resources, you need to add unmanaged resources to your executable. In parapura's screenshot, you need to select the Resource file
radio button. That requires a .res file, a binary file that's created by running the Windows SDK rc.exe tool on a .rc file. The .rc file is a simple text file that contains resource statements, similar to this:
1 ICON "mainicon.ico"
2 ICON "alternative1.ico"
3 ICON "alternative2.ico"
1 24 "app.manifest"
Be sure to save this file into your project folder without utf-8 encoding, using Notepad is best. Create the required app.manifest file with Project + Add New Item, Application Manifest File. Add this .rc file to your project with Project + Add Existing Item. Double-click it and verify that you can see the icons and the manifest. Right-click the top node, Add Resource and click Version + New. Edit the version info, beware that it will no longer automatically match the attributes in AssemblyInfo.cs
You can compile the .rc file into a .res file with the Visual Studio Command prompt:
rc /r something.rc
Which produces the .res file you can use in the project property tab. Doing this is a pre-build event is advisable but a bit hard to get right. The number of ways this can go wrong are numerous, good luck.
Multiple Icons into c# 2.0 WinApp
I decided to put all icons into separate old-school plain win32 c++ *.dll.
It's more convienient and I don't need to do any tricks with versioninfo/win32resources.
Automatically embed multiple icons in a .NET Executable
I've just created a simple tool to do exactly this without having to mess with .res files. It is a tiny utility which you can use as part of your Post-Build event and lets you add all icon files in a particular folder to your assembly. If we assume that you have a icons folder under your main project folder you can add the following post-build event:
C:\path\to\InsertIcons.exe $(TargetPath) $(ProjectDir)icons
A further description and a download can be found at http://einaregilsson.com/add-multiple-icons-to-a-dotnet-application/
Multiple icons in executable in VS2010
This works for me:
http://www.codeproject.com/Tips/160885/How-to-Embed-Multiple-Icons-and-Color-Animated-Cur.aspx
embed .res file as a native win 32 resource into c# application
It is supported, Project > Properties > Application tab, "Resource file" setting.
Avoiding duplicate icon resources in a .NET (C#) project
Yeah, it's pretty annoying. But the problem with the proposed answer of Icon.ExtractAssociatedIcon is that it will retrieve the 32x32 icon, and then downsample to a 16x16 icon in your forms window or on the taskbar, which will look terrible unless your 32x32 icon is very cleverly constructed.
The way I'm doing it is with interop (put the first line in your form constructor):
this.Icon = ExtractSmallIconFromLibrary(Application.ExecutablePath);
...
public static Icon ExtractSmallIconFromLibrary(string file) {
IntPtr[] reficon = new IntPtr[1];
int nextracted = ExtractIconEx(file, 0, null, reficon, 1);
if (nextracted < 1)
return null;
Icon unmanaged_icon = Icon.FromHandle(reficon[0]);
Icon icon = (Icon)unmanaged_icon.Clone();
DestroyIcon(unmanaged_icon.Handle);
return icon;
}
[DllImport("Shell32", CharSet = CharSet.Auto)]
extern static int ExtractIconEx(
[MarshalAs(UnmanagedType.LPTStr)]
string lpszFile,
int nIconIndex,
IntPtr[] phIconLarge,
IntPtr[] phIconSmall,
int nIcons
);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);
But this isn't great, either, since you do want the 32x32 icon for things like the Alt-Tab icon list. So you really need to extract the entire icon, which is a bigger job. Maybe there's a straightforward way to combine the two icons into one. Or you can do like this codeproject program, which extracts the whole icon in the first place with a huge pile of code.
Any easy way to use icons from resources?
choosing that file, will embed the icon in the executable.
Related Topics
Why Gettype Returns System.Int32 Instead of Nullable<Int32>
Linq - What Is the Quickest Way to Find Out Deferred Execution or Not
How to Remove Numbers from String Using Regex.Replace
Why Visual Studio Doesn't Create a Public Class by Default
How to Programmatically Create, Read, Write an Excel Without Having Office Installed
C# Datetimes: Conversion for Different Time Zones
Download Feature Not Working Within Update Panel in ASP.NET
How to Get a Dimension (Slice) from a Multidimensional Array
Text Property in a Usercontrol in C#
How to Get Current Regional Settings in C#
How to Inject an Attribute Using a Postsharp Attribute
How to Simply 'Read' a File That Is in Use
Is Using an an 'Async' Lambda with 'Task.Run()' Redundant
No Access to the Session Information Through Signalr Hub. Is My Design Is Wrong