0

Could any one help me solve this problem. I have FlowLayoutPanel and in it I have multiple UserControls. Have enabled auto scrolling. Problem I have is UserControls are flickering/blinking on scrolling. I understand this is because OnPaint event. I have tried folowing code. Have derivated from FlowLayoutControl and trying to override WndProc but without success.

class ScrollFlowLayoutPanel : FlowLayoutPanel
{
    private const int WM_HSCROLL = 0x114;
    private const int WM_VSCROLL = 0x115;

    protected override void WndProc(ref Message m)
    {
        if ((m.Msg == WM_HSCROLL || m.Msg == WM_VSCROLL) && (((int)m.WParam & 0xFFFF) == 5))
        {   
            // Change SB_THUMBTRACK SB_THUMBPOSITION         
            m.WParam = (IntPtr)(((int)m.WParam & ~0xFFFF) | 4);
        }

        base.WndProc (ref m);
    } 
}

Thanks

MatejKr
  • 115
  • 12
  • 1
    Scrolling is heavily optimized, a control simply gets another Location property value and *no* painting event is generated, the pixels of the control are blitted. Unless a part of the control scrolls into view, you then get a paint for *only* the sliver that became visible. A millisecond, give or take. If that still causes visible flicker then you are doing something very wrong, impossible to guess what that might be from the question. You can flip the ignore bit by turning on compositing in the main form, [this post shows how](http://stackoverflow.com/a/89125/17034). – Hans Passant Jan 26 '16 at 13:35
  • Without using method you posted scrolling is smoth but controls flicker. With using posted code controls dont flicker but scrolling becomes slow and kinda jumpy/jamming. – MatejKr Jan 26 '16 at 14:04
  • 1
    Have you tried setting `DoubleBuffered` to `true` on the form? – Balah Jan 26 '16 at 16:08
  • It was my error, I was using loop in a user control Paint event wich caused control to slowly paint it self. The solution to blinking problem is definitly: [link](http://stackoverflow.com/a/89125/17034) – MatejKr Jan 26 '16 at 22:02

0 Answers0