开发者

Transparency drawing compounds layers instead of redrawing

I have a custom control in which I am overriding the following method to create a transparent background:

    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 cal开发者_运维问答ling this.Invalidate.

The transparency is being rendered correctly, but every time it renders it renders over top of the last render instead of redrawing. This causes the glow to get more and more intense until its just a big blob. How do I fix this?


I solved it by keeping a bool as to whether or not there was a gradient that needed to be removed or not before re-drawing.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜