Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smooth scrolling .net forms

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?

like image 589
FatDaemon Avatar asked Dec 14 '22 02:12

FatDaemon


2 Answers

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);
}
like image 95
CharlesW Avatar answered Dec 16 '22 16:12

CharlesW


If you don't want to use WinAPI calls, you can do this:

// Add event handler to an existing panel
MyPanel.Scroll += new EventHandler(MyPanelScroll_Handler);

// Enables immediate scrolling of contents
private void MyPanelScroll_Handler(System.Object sender, System.Windows.Forms.ScrollEventArgs e)
{
    Panel p = sender As Panel;
    if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
        p.HorizontalScroll.Value = e.NewValue;
    } else if (e.ScrollOrientation == ScrollOrientation.VerticalScroll) {
        p.VerticalScroll.Value = e.NewValue;
    }
}
like image 41
alldayremix Avatar answered Dec 16 '22 17:12

alldayremix