During FlowLayoutPanel scrolling, background distorts + flickers

前端 未结 5 1457
醉梦人生
醉梦人生 2020-12-17 14:39

I have a windows form application that has a background. Within it, I have a flowlayoutpanel with a transparent background. When I scroll, the following happens:

5条回答
  •  抹茶落季
    2020-12-17 15:37

    I am very pleased to report that Hans, and the internet at large (just learn WPF....pfffft), is wrong here.

    The problem is in the WM_HSCROLL and WM_VSCROLL events. Through some trial and error, I found that, if I dragged the scroll bar fast enough, I was able to move a ghost copy of my background over the actual background which was fxied how I wanted it. So whatever is happening inside the scrollable control, Windows is able to keep up and some out of sync redraw is what's causing the shearing.

    So how do you solve this problem?

    1. Set your scrollable control to DoubleBuffered.

    2. Catch the WM_HSCROLL/WM_VSCROLL messages. Invalidate. Set the "do_not_paint" flag to true. Call the base.WndProc(). Set the "do_not_paint" flag to false. Update.

    3. Catch the WM_PAINT and related messages. Only call base.WndProc() if the "do_not_paint" flag is false.

    What this does is allow the scrollable control to do whatever layout calculations and scrollbar repositioning it needs to do but doesn't let it redraw anything that would trigger the shearing effect.

提交回复
热议问题