How to eliminate flicker in Windows.Forms custom control when scrolling?

后端 未结 4 1578
攒了一身酷
攒了一身酷 2020-12-01 19:22

I want to create a custom control in C#. But every time I have to fully redraw my control, it flickers, even if I use double buffering (drawing to an Image first, and blitti

4条回答
  •  独厮守ぢ
    2020-12-01 19:57

    It may be good enough to just call

    SetStyle(ControlStyles::UserPaint | ControlStyles::AllDrawingInWmPaint, true);
    

    The flickering you are seeing most likely because Windows draws the background of the control first (via WM_ERASEBKGND), then asks your control to do whatever drawing you need to do (via WM_PAINT). By disabling the background paint and doing all painting in your OnPaint override can eliminate the problem in 99% of the cases without the need to use all the memory needed for double buffering.

提交回复
热议问题