1

Is it possible for us to turn WS_EX_COMPOSITED on ONLY when a Panel/Container Control is being scrolled, then turning it off? Having it activated for the whole lifespan of the application, affects every controls surrounding my application, I only need it activated when the Panel it's being scrolled.

Something like that:

    private int originalExStyle = -1;
    private bool _scrolling = false;

    protected override CreateParams CreateParams
    {
        get
        {

            if (originalExStyle == -1)
                originalExStyle = base.CreateParams.ExStyle;

            CreateParams cp = base.CreateParams;

            if (_scrolling)
                cp.ExStyle |= 0x02000000; // Turn on
            else
                cp.ExStyle = originalExStyle; // Reset to original state

            return cp;
        }
    }

    protected override void OnScrollBegin(ScrollEventArgs se)
    {
        base.OnScrollBegin(se);
        _scrolling = true;
        RecreateHandle();
    }

    protected override void OnScrollEnd(ScrollEventArgs se)
    {
        base.OnScrollEnd(se);
        _scrolling = false;
        RecreateHandle();
    }
Dezv
  • 156
  • 1
  • 8
  • Please don't `RecreateHandle();` like that. Maybe you just need to double buffer the container by enabling its `DoubleBuffered` property rather than applying the `WS_EX_COMPOSITED` style which double buffers everything it contains. Read [this](https://stackoverflow.com/a/25878263/14171304) for more. As an alternative to `CreateParams` to add/remove a style/flag, you could use the `GetWindowLongPtr` and `SetWindowLongPtr` functions. – dr.null Nov 24 '20 at 15:27
  • Thanks! And yes, I am aware of it, it was just an example and the only known option to me of re-calling the CreateParams method, maybe UpdateStyles would've worked too.I will most likely just let it be double buffered, and one day I will create a custom scrolling handling (hiding controls outside of viewport, etc.). Activating WS_EX_COMPOSITED is terrible. – Dezv Nov 24 '20 at 16:24

0 Answers0