Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>ResourceManager</code> loads the icon based on the bits stored in the resources. However, the way it handles loading won't let you access the 256x256 icon (this information does not make its way into the <code>System.Drawing.Icon</code> that you are getting back).</p> <p>I am sorry to disappoint you, but the only way which works that I am aware of is to load the icon through a P/Invoke of <code>LoadImage</code> and working with a file (yes, I know, that's not what you were looking for). So the new question should be: how do I extract the bits of a given resource so that I can store them to a file? I fear that this isn't possible either, having done some stepping through <code>System.Resources.ResourceReader</code>, as the resource data seems to be a collection of serialized .NET objects.</p> <p>Anyway, for those who can afford to load the icon from a .ICO file (and for myself, as a future reference on how to load 256x256 icons), call <code>IconConverter.LoadIcon</code>:</p> <pre><code>using System.Runtime.InteropServices; static class IconConverter { public static System.Drawing.Icon LoadIcon(string path, int width, int height) { System.IntPtr hIcon; hIcon = LoadImage (System.IntPtr.Zero, path, IMAGE_ICON, width, height, LR_LOADFROMFILE); if (hIcon == System.IntPtr.Zero) { return null; } return System.Drawing.Icon.FromHandle (hIcon); } const int IMAGE_ICON = 1; const int LR_LOADFROMFILE = 0x0010; [DllImport ("user32.dll", SetLastError=true, CharSet=CharSet.Auto)] static extern System.IntPtr LoadImage(System.IntPtr hInstance, string lpszName, uint uType, int cxDesired, int cyDesired, uint fuLoad); } </code></pre> <p>Once you have the <code>System.Drawing.Icon</code> in the expected size, just paint it using <code>graphics.DrawIconUnstretched</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload