views:

328

answers:

1
[DllImport("user32.dll")]
public static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw);
[DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern int GetScrollPos(int hWnd, int nBar);

So those are the externs im using to move the scroll position, what im doing, is i get the current position, and add or substract an exact amount of pixels, and the scroll bar on my form moves perfectly how i want it, but the content in the control stays stationary. What is the problem here?

A: 

I found the correct API call! :)

    public void ScrollTo(int Position)
    {
        SetScrollPos((IntPtr)this.Handle, 0x1, Position, true);
        PostMessageA((IntPtr)this.Handle, 0x115, 4 + 0x10000 * Position, 0);
    }

before i was just using SetScrollPos, but this combined with PostMessageA works perfectly

Tommy
You are breaking the contract for WM_VSCROLL, it never is sent without an SB_ENDSCROLL. Use the AutoScrollPosition property to control the scrollbar position.
Hans Passant
@nobugs: would you like to elaborate on how i can fix my problem, or post your own answer?
Tommy