0
[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?

Peter Lang
  • 54,264
  • 27
  • 148
  • 161
caesay
  • 16,932
  • 15
  • 95
  • 160
  • 2
    What control are you scrolling? Also, why isn't the second `hWnd` parameter an `IntPtr`? – SLaks Mar 08 '10 at 14:52
  • 1
    If you are interacting with a Winforms application then there should be no need to use P/Invoke — you should be able to do everything you need using the .NET API provided by the controls. Could you give a bit more detail about your application? – Paul Ruane Mar 08 '10 at 15:00
  • 1
    it's a custom built UserControl, it has no methods that can control the scroll to the precision I need – caesay Mar 08 '10 at 16:28

1 Answers1

0

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

caesay
  • 16,932
  • 15
  • 95
  • 160
  • 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 Mar 09 '10 at 22:33
  • 3
    @nobugs: would you like to elaborate on how i can fix my problem, or post your own answer? – caesay Mar 10 '10 at 02:02