i have an ico file that contains a 48x48 and a 256x256 Vista PNG version (as well as the 32x32 and 16x16 versions). i want to draw the icon using the appropriate internal size version.
i've tried:
Icon ico = Properties.Resources.TestIcon;
e.Graphics.DrawIcon(ico, new Rectangle(0, 0, 48, 48));
e.Graphics.DrawIcon(ico, new Rectangle(48, 0, 256, 256));
But they draw the 32x32 version blown up to 48x48 and 256x256 respectively.
i've tried:
Icon ico = Properties.Resources.TestIcon;
e.Graphics.DrawIconUnstretched(ico, new Rectangle(0, 0, 48, 48));
e.Graphics.DrawIconUnstretched(ico, new Rectangle(48 0, 256, 256));
But those draw the 32x32 version unstretched.
i've tried:
Icon ico = Properties.Resources.TestIcon;
e.Graphics.DrawImage(ico.ToBitmap(), new Rectangle(0, 0, 48, 48));
e.Graphics.DrawImage(ico.ToBitmap(), new Rectangle(48, 0, 256, 256));
But those draw a stretched version of the 32x32 icon.
How do i make the icon draw itself using the appropriate size?
Additionally, i want to draw using the 16x16 version. i've tried:
Icon ico = Properties.Resources.TestIcon;
e.Graphics.DrawIcon(ico, new Rectangle(0, 0, 16, 16));
e.Graphics.DrawIconUnstretched(ico, new Rectangle(24, 0, 16, 16));
e.Graphics.DrawImage(ico.ToBitmap(), new Rectangle(48, 0, 16, 16));
But all those use the 32x32 version scaled down, except for the Unstretched
call, which crops it to 16x16.
How do i make the icon draw itself using the appropriate size?
Following schnaader's suggestion of constructing a copy of the icon with the size you need doesn't work for 256x256 size. i.e. the following does not work (it uses a scaled version of the 48x48 icon):
e.Graphics.DrawIcon(
new Icon(ico, new Size(256, 256)),
new Rectangle(0, 0, 256, 256));
While the following two do work:
e.Graphics.DrawIcon(
new Icon(ico, new Size(16, 16)),
new Rectangle(0, 0, 16, 16));
e.Graphics.DrawIcon(
new Icon(ico, new Size(48, 48)),
new Rectangle(0, 0, 48, 48));