This blog will describe some of the learning experiences that I have with .NET, some personal projects that I'm working on, and whatever other topics tickle my fancy.
My Blog Links
Tuesday, March 02, 2004
You know some things are just harder than they should be. I was trying to draw an Image so that it would paint with the selection color, as needed. That way, if the item was selected, its background would composite draw with the selection. You've probably seen this type of functionality in all sorts of WinForms controls. Since a picture is worth a 1000 words, here goes:
My control had an ImageList attached. On the ImageList, the TransparentColor was set to white. So, I thought if I used ImageList.Draw, it would paint it correctly given the TransparentColor. That way when an item was selected, the image would paint with the selection color for the bits of the image that had the transparent color.
Well, needless to say, that didn't work. I had to call the right incarnation of Graphics.DrawImage (mainly one that took an ImageAttributes as a parameter). By setting the right ColorKey in the ImageAttributes, it finally painted correctly. Here's the code:
Comments: Post a Comment