Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Forms .NET 2.0: How to draw a PNG icon?
    text
    copied!<p><strong>Note:</strong> Question <a href="https://stackoverflow.com/questions/220465/using-256-x-256-vista-icon-in-application">Using 256 x 256 Vista icon in application</a> deals with using a "Vista" icon as the application's icon. This question deals with manually painting a Vista icon.</p> <p><strong>Note:</strong> Question <a href="https://stackoverflow.com/questions/281999/winforms-net-20-how-to-paint-with-the-proper-icon">WinForms .NET 2.0: How to paint the proper sized icon?</a> deals with painting a Vista icon loaded from a file. This question deals with painting a Vista icon that is loaded from a .resource.</p> <hr> <p>I've included an icon in my Visual Studio project that has various formats:</p> <ul> <li>16x16</li> <li>32x32</li> <li>48x48</li> <li>256x256 (PNG compressed)</li> </ul> <p>Now want to draw the 256x256 version. None of the following things I've tried work.</p> <p><strong>The following draws the 32x32 format stretched to 256x256:</strong></p> <pre><code>Icon ico = Properties.Resources.TestIconThatHasA256PNGFormat; e.Graphics.DrawIcon(ico, new Rectangle(0, 0, 256, 256)); </code></pre> <p><strong>The following draws the 32x32 format unstretched:</strong></p> <pre><code>Icon ico = Properties.Resources.TestIconThatHasA256PNGFormat; e.Graphics.DrawIconUnstretched(ico, new Rectangle(0, 0, 256, 256)); </code></pre> <p><strong>The following draws the 32x32 format stretched to 256x256:</strong></p> <pre><code>Icon ico = Properties.Resources.TestIconThatHasA256PNGFormat; e.Graphics.DrawImage(ico.ToBitmap(), new Rectangle(0, 0, 256, 256)); </code></pre> <p><strong>The following draws the 48x48 format stretched to 256x256:</strong></p> <pre><code>Icon ico = Properties.Resources.TestIconThatHasA256PNGFormat; e.Graphics.DrawIcon( new Icon(ico, new Size(256, 256)), new Rectangle(0, 0, 256, 256)); </code></pre> <p>How do I draw the 256x256 format icon?</p> <hr> <p>Notes:</p> <ol> <li><p>The icon is not coming from a file, so <a href="https://stackoverflow.com/questions/220465/using-256-x-256-vista-icon-in-application">PInvoking</a> LoadImage() will not help.</p></li> <li><p>The icon is not the icon associated with a file, so <a href="http://support.microsoft.com/kb/319350" rel="nofollow noreferrer">PInvoking</a> SHGetFileInfo() <a href="https://stackoverflow.com/questions/287041/winforms-net-20-how-to-draw-a-vista-icon#287076">will</a> not help. Nor will <a href="https://stackoverflow.com/questions/220465/using-256-x-256-vista-icon-in-application">using Icon.ExtractAssociatedIcon</a>.</p></li> <li><p>I'm also not trying to author icons with a 256x256 format at runtime, so <a href="http://www.codeproject.com/KB/cs/IconLib.aspx" rel="nofollow noreferrer">libraries designed to do that</a> will not help.</p> <p><a href="https://stackoverflow.com/questions/281999/winforms-net-20-how-to-paint-with-the-proper-icon">2</a>: Question <a href="https://stackoverflow.com/questions/281999/winforms-net-20-how-to-paint-with-the-proper-icon">WinForms .NET 2.0: How to paint the proper sized icon?</a></p></li> </ol>
 

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