Drag & Drop w/Translucency...

  • Thread starter Thread starter Paul Colton
  • Start date Start date
P

Paul Colton

I have created my own drag/drop cursor for dragging around an image, but how
can I make my cursor translucent (ie. alpha blended) like Windows XP does
when you drag around an icon?

Thanks.
 
You are right, the cursor pointer itself is not transparent, but the icon
attached to it is -- any hints on how to "properly" do this?
 
Hi Paul,

To draw a transparent image you can use one of the Graphics.DrawImage
overloads that takes ImageAttributes as a parameter.
when you create an ImageAttribute object you can set a ColorMatrix for
transformating the colors. The color matrix work on the same way as the
other transformation matrices. The difference is that it is applied on the
color vector which is RGBAw (where the A is the alpha component and w is
always 1). I think that MSDN documentation wrongly states that the vector is
ARGBw.
Anyway, if you prepare a scaling matrix, which scales only the A component
of the color vector it will be like you are drawing an translucent image.

The code might be something like this:
ImageAttributes ia = new ImageAttributes();
ColorMatrix cm = new ColorMatrix();
cm.Matrix33 = 0.5F; //50% transparency
ia.SetColorMatrix(cm);

using( Graphics g = CreateGraphics())
{
using(Bitmap bmp = new Bitmap(@"path to some image file"))
{
g.Clear(this.BackColor);
g.DrawImage(bmp, this.ClientRectangle, 0, 0, bmp.Width, bmp.Height,
GraphicsUnit.Pixel, ia);
}
}

BTW The image atributes has more properties, which I believe can be used for
some cool effects

HTH
B\rgds
100
 
Back
Top