troubleshooting Question

Winforms Drag & Drop image with transparency

Avatar of Russ Suter
Russ Suter asked on
C#.NET Programming
4 Comments1 Solution214 ViewsLast Modified:
I have the following code:
        private void button1_MouseDown(object sender, MouseEventArgs e)
            Button btn = sender as Button;
            using (Bitmap bmp = new Bitmap(btn.Width, btn.Height))
                btn.DrawToBitmap(bmp, new Rectangle(Point.Empty, btn.Size));
                using (Graphics gfx = Graphics.FromImage(bmp))
                    ColorMatrix matrix = new ColorMatrix();
                    matrix.Matrix33 = .5F;
                    ImageAttributes attributes = new ImageAttributes();
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                    gfx.DrawImage(bmp, new Rectangle(Point.Empty, bmp.Size));
                    Cursor cur = new Cursor(bmp.GetHicon());
                    Cursor.Current = cur;

Open in new window

It's supposed to draw the image with transparency but it's opaque. How do I add alpha channel info? My ultimate goal is to have an alpha channel gradient so the transparency increases as the image gets further away from a given point (usually the center or the left edge).
Karrtik Iyer
Software Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004