Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView onScroll event

I’m programming one easy C# application, and i need onScroll event on Listview. So i created class ListviewEx witch inherits original ListView. I found how to detect scroll message from WinAPI and i modified WndProc method. Now i have this WndProc:

protected override void WndProc(ref Message m) 
{ 
    base.WndProc(ref m); 

    if (m.Msg == WM_VSCROLL) 
    { 
        onScroll(this, new EventArgs()); 
    } 
}

But problem is, that I dont know how to detect information about scrolling. This data should be in WParam, but in C# is no LOWORD macro like in C++ and i need switch to detect parameters like SB_ BOTTOM, SB_ ENDSCROLL, SB_PAGEUP etc.

Is there any way how to replace LOWORD macro in C# ?

Or other way how to detect necessary parameters about scrolling?

like image 388
Klinki Avatar asked Jul 24 '09 09:07

Klinki


People also ask

What is Onscroll event?

The onscroll event occurs when an element's scrollbar is being scrolled. Tip: use the CSS overflow style property to create a scrollbar for an element.

How do you stop an Onscroll event?

onscroll event fires when the window has been scrolled. Overriding this function and setting it to a fixed position every time the scroll happens will effectively disable the scroll effect. The current scroll position from the top is found by using the window. pageYOffset and the document.

How do I listen to scroll position in flutter?

I used NotificationListener that is a widget that listens for notifications bubbling up the tree. Then use ScrollEndNotification , which indicates that scrolling has stopped. For scroll position I used _scrollController that type is ScrollController .

How do you get the last scroll position in flutter?

Output Screen: In this way, you can fetch the current scroll position of SingleChildScrollView() or ListView() or set Scroll Position change Listener in Flutter App.


1 Answers

You can define WParam constants as followed:

private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;

private const int SB_HORZ = 0;
private const int SB_VERT = 1;

private const int SB_LINELEFT = 0;
private const int SB_LINERIGHT = 1;
private const int SB_PAGELEFT = 2;
private const int SB_PAGERIGHT = 3;
private const int SB_THUMBPOSITION = 4;
private const int SB_THUMBTRACK = 5;
private const int SB_LEFT = 6;
private const int SB_RIGHT = 7;
private const int SB_ENDSCROLL = 8;

private const int SIF_TRACKPOS = 0x10;
private const int SIF_RANGE = 0x1;
private const int SIF_POS = 0x4;
private const int SIF_PAGE = 0x2;
private const int SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;

The actual code to inspect the WParam would be something like this:

if (m.Msg == WM_VSCROLL)
{

        ScrollInfoStruct si = new ScrollInfoStruct();
        si.fMask = SIF_ALL;
        si.cbSize = (uint)Marshal.SizeOf(si);
        GetScrollInfo(msg.HWnd, SB_VERT, ref si);
        if (msg.WParam.ToInt32() == SB_ENDSCROLL)
        {
            ScrollEventArgs sargs = new ScrollEventArgs(ScrollEventType.EndScroll, si.nPos);
            onScroll(this, sargs);
        }
}

pinvoke.net is a great site to get the constant values used in windows32 API without having to inspect header files yourself.

See this example

like image 129
Martijn Laarman Avatar answered Sep 17 '22 16:09

Martijn Laarman