Alright, here's the deal..I have 32bit alpha blended XP icons that i'm using in a control...
I'm using a manifest for comctl v6, which I read was the solution..but I cannot make Images that come from an ImageList to work with transparency..i know it's not the icons because i can use the *SAME* Icon using GDI+ DrawIcon() and it works perfectly fine. I'm very desperate for a solution, and i have sample apps if needed..please help me out..
-Randy

I've beaten my head against the wall for 7 hours on this Icon problem..HELP?
Sung M Kim
the left is normal tabcontrol
the right is ownerdrawn
coming from the same imagelist and all
heres the call to draw it:
e.Graphics.DrawImage(this.ImageList.Images[this.TabPages[e.Index].ImageIndex],e.Bounds.Left+2,e.Bounds.Top+vOffset);
ideas
Avocado
randy.w@softworks.ca
R2ks
or maybe it's a waste of time, just thought I'd throw it out anyway.
Warren Read - MSFT
now here's the question..if i want to use owner drawn items..what's the best approach for being able to draw the images in the correct format
using DrawImage() isnt working properly, it draws them with the incorrect format..
do i need to use Bitmap and lock the bits like discussed one one of the forums i don't mind doing that if necessary, but if i don't have to i don't feel the need to....any ideas
Pedro Martins
Ashish P. Ruparel
[StructLayout(LayoutKind.Explicit)]
public struct RECT
{
[FieldOffset(0)] public int left;
[FieldOffset(4)] public int top;
[FieldOffset(8)] public int right;
[FieldOffset(12)] public int bottom;
}
[DllImport("uxtheme.dll")]
private static extern IntPtr OpenThemeData (IntPtr hWnd, [MarshalAs(UnmanagedType.LPTStr)] string pszClassList);
[DllImport("uxtheme.dll")]
private static extern IntPtr CloseThemeData (IntPtr hTheme);
[DllImport("uxtheme.dll")]
private static extern IntPtr DrawThemeIcon(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, ref RECT pRect, IntPtr himl, int iImageIndex);
private void DrawThemeIconEx(Graphics g, ImageList il, int ImageIndex, int x, int y, int width, int height)
{
RECT rect = new RECT();
rect.left = x;
rect.top = y;
rect.right = x+width;
rect.bottom = y+height;
IntPtr hData = OpenThemeData(this.Handle,"Button");
IntPtr hDC = g.GetHdc();
DrawThemeIcon(hData,hDC,1,1,ref rect,il.Handle,ImageIndex);
g.ReleaseHdc(hDC);
CloseThemeData(hData);
}
e6matt
Smart Akhtar
You could try DrawImageUnscaled() if it is a scaling issue.
- mike
adrianf
[StructLayout(LayoutKind.Explicit)]
private struct RECT
{
[FieldOffset(0)] public int left;
[FieldOffset(4)] public int right;
[FieldOffset(8)] public int top;
[FieldOffset(12)] public int bottom;
}
[DllImport("uxtheme.dll")]
private static extern IntPtr OpenThemeData(IntPtr hWnd, [MarshalAs(UnmanagedType.LPTStr)] string pszClassList);
[DllImport("uxtheme.dll")]
private static extern IntPtr CloseThemeData(IntPtr hTheme);
[DllImport("uxtheme.dll")]
private static extern IntPtr DrawThemeIcon(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, ref RECT pRect, IntPtr himl, int iImageIndex);
<...> then in my function call:
RECT prect = new RECT();
prect.left = myRect.Left;
prect.right = myRect.Right;
prect.top = myRect.Top;
prect.bottom = myRect.Bottom;
IntPtr hData = OpenThemeData(this.Handle,"Button");
IntPtr hDC = myGraphics.GetHdc();
DrawThemeIcon(hData, hDC, 0, 0, ref prect, myImageList.Handle, myIndex);
myGraphics.ReleaseHdc();
..This seems to be working fine except for one thing, i cant force it to draw the images as black and white (disabled) which i believe has something to do with the iPartId and iStateId, i copied the enums over to C# but still no success on that..so if anyone has any suggestions please let me know. previously i was using ControlPaint.DrawImageDisabled() ..so maybe mike could you look at your DrawImageDisabled () function and see how it makes it a black and white Thanks! Hope this helps in the least bit!
SealedSun.ch
ControlPaint's DrawImageDisabled uses one of the Graphics.DrawImage overloads that takes a ColorMatrix. So you're basically in the same position you were in before, using DrawImage on an Icon doesn't work too well. And there is no overload of DrawIcon that takes a ColorMatrix.
I really can't think of a good way to do this. You could try to get the pixel info from the image and then create an in memory icon, but you'd need to get pretty low level and undersatnd the memory layout of each format.
- mike
Srini Satrasala
Sanderb
- mike
David Mullin
OptikConnex
So emulating what our TabControl does is out. Below is some code I've used to draw an Icon.
Icon ico = new Icon(this.Icon,16,16);
Rectangle iconRect = new Rectangle(3, 2, 16, 16);
pe.Graphics.DrawIconUnstretched(ico, iconRect);
This is actually a modified version of some code you posted here a while back. <a href="http://windowsforms.net/Forums/ShowPost.aspx tabIndex=1&tabId=41&PostID=594">http://windowsforms.net/Forums/ShowPost.aspx tabIndex=1&tabId=41&PostID=594</a>
The key is that you need to treat these as Icons and not as Images for GDI+ to draw them correctly. Instead of using an ImageList, just use a collection of Icons.
BTW - has anyone ever written any code to take an Icon in an ImageList and convert it back to an Icon This would be some useful code, especially here.
- mike