views:

40

answers:

1

So i have this control, and im overriding it to create a transparent background with this:

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x20;
            return cp;
        }
    }

On the paint method, im doing this:

    protected override void OnPaint(PaintEventArgs p)
    {
        base.OnPaint(p);
        Graphics e = p.Graphics;
        this.Size = Resources.CenterButtonHover.Size;
        if (mousedown)
        {
            e.DrawImage(Resources.CenterButtonDown, new Point(0, 0));
        }
        else if (hover)
        {
            e.DrawImage(Resources.CenterButtonHover, new Point(0, 0));
        }
        else
        {
            e.DrawImage(Resources.CenterButtonNormal, new Point(4, 4));
        }
        e.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    }

And on the various mouse events in calling this.Invalidate.

What is happening, is two of the images it paints, have a transparent glow on them, and what seems to be happening, is that the images are just being repainted on top of eachother, instead of clearing and painting a new one, and every time a new image is painted, the transparent glow builds more and more.. and eventually the whole thing is just a big blob. how do i fix this?

+2  A: 

I solved it by keeping a bool as to weather or not there was a gradient that needed to be removed or not before re-drawing. this is how i redrew:

        if (needsreset)
        {
            this.SuspendLayout();
            this.Region = new Region(this.ClientRectangle);
            needsreset = false;
            return;
        }
Tommy