Transparency draws connection layers instead of redrawing

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

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

In the drawing method, im does the following:

    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 various mouse events when called this.Invalidate.

Transparency is rendered correctly, but each time it displays it, on top of the top of the render instead of redrawing. This leads to the fact that the glow becomes more intense until it becomes just a big blob. How to fix it?

+3
source share
1 answer

, bool , , , .

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

Source: https://habr.com/ru/post/1764269/


All Articles