2

I have a form that has many custom controls on that had a terrible flicker, I found the following code (here on stackoverflow whilst searching for a solution, How to fix the flickering in User controls or Winforms Double Buffering posted by Hans Passant) which fixed the flicker

protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
        return cp;
    }
}

However, now if I click the position bar on the scrollbar, the position bar stays fixed, until I let go of the mouse button.

Is there a way to have the scroll position bar update whilst being dragged and not have flicker on the controls?

Many thanks

Community
  • 1
  • 1
Martin
  • 837
  • 1
  • 10
  • 18
  • Attribution is required here. http://meta.stackexchange.com/questions/24611/is-it-legal-to-copy-stack-overflow-questions-and-answers – Hans Passant Dec 01 '12 at 15:12
  • 1
    Have edited the question to say I found the above code here, actually I believe it was one of your posts. Have found and added the URLs and it was in fact you, thank you :) – Martin Dec 02 '12 at 15:33

1 Answers1

1

smooth scrolling .net forms

Answer found here, all thanks to CharlesW

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 to SB_THUMBPOSITION
        m.WParam = (IntPtr)(((int)m.WParam & ~0xFFFF) | 4);
    }
base.WndProc (ref m);
}
Community
  • 1
  • 1
Martin
  • 837
  • 1
  • 10
  • 18