I’m trying to create a semi-transparent user control button whose background opacity changes from 30% black to 70% black on mouseEnter. I can successfully paint the button 30% black but I can’t go from 70% to 30%. It’s as if every time OnPaint() is called, it paints over what was already there instead of starting from scratch. I use a subclassed Panel as the user control’s background.
Here’s my OnPaint method for the subclassed Panel:
Graphics g = e.Graphics;
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
Brush brush = new SolidBrush(Color.FromArgb(Alpha, Color.Black)); // alpha is set by me
g.FillRectangle(brush, rect);
g.Dispose();
I’ve played with g.Clear() and g.Restore() but haven’t had any luck. Any ideas?
Thanks!
I ended up solving this by swapping 30% opaque black and 70% opaque black assets for the background image. I also set the button’s BackColor to Color.Transparent.