smooth scrolling .net forms

FatDaemon picture FatDaemon · Sep 15, 2009 · Viewed 7.5k times · Source

Hi I am using forms in .net and i am adding lots of linked labels dynamically during runtime, I am adding these linklabels to panel and adding that panel to the winform. When the no of linklabels increases the form puts out an auto scrollbar(vertical)... Now when i scroll down using that autoscroll the form is not updating its view as i scroll, the form gets refreshed only when i stop scrolling... Also when it refresh it looks too bad.. i can see how it draws slowly....

Has anyone dealt with this before??

I tried form.refresh() in scroll event handler but that doesn't seem to help..

Any clues?

Answer

CharlesW picture CharlesW · Mar 21, 2012

Pop this into your class (UserControl, Panel, etc) , then it will work with thumb drag.

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);
}