Tuesday, January 10, 2006

.NET : Smooth Scrolling Panel

Windows raises ThumbTrack ScrollEvent while dragging Scrollbar. And if your System Visual Effects are optimized for performance, window contents are updated only when scollbar stops ( unlike browser)- that looks ugly and annoying.

To solve this I just substituted all SB_THUMBTRACK messeges with SB_THUMBPOSITION. Not very pretty, but works. The following code is in C#.

public class ScrollPanel : System.Windows.Forms.Panel
{
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);
}
}

3 Comments:

At 10:12 AM, Anonymous Anonymous said...

Very very good!!!
It´s realy works!!!

For now, it´s the only method, that a could find, to resolve that problem.

thanks!

 
At 3:27 PM, Blogger Malcolm Hall said...

Works great thanks! With this you can turn a FlowLayoutPanel into a perfect looking customisable list view.

 
At 7:50 AM, Anonymous Chris said...

Works great exactly what I was looking for. Thanks a lot !

 

Post a Comment

<< Home