Question

I'm creating a User Control for WinForms and have the need to scroll a section of the control window.

Inexplicably, it appears no ScrollWindow() method is available in WinForms. So I'm trying to use InteropServices to use the Win32 API ScrollWindow() function using variations of the following:

[StructLayout(LayoutKind.Sequential)] 
public struct RECT
{
    public int left; 
    public int top; 
    public int right; 
    public int bottom; 

    public RECT(Rectangle rect)
    {
        this.bottom = rect.Bottom;
        this.left = rect.Left;
        this.right = rect.Right;
        this.top = rect.Top;
    }
}

[DllImport("user32")]
public static extern int ScrollWindow(IntPtr hWnd, int nXAmount, int nYAmount,
    ref RECT rectScrollRegion, ref RECT rectClip);

void MyScrollFunc(int yAmount)
{
    RECT r = new RECT(ClientRectangle);
    ScrollWindow(Handle, 0, yAmount, ref r, ref r);
}

The result is that this code does absolutely nothing. I've tried all sorts of variations of this code, including calling Update() after the scroll (which shouldn't be necessary).

ScrollWindow() is returning 1, which signifies success but it simply has no effect on the content of the control window no matter what I try.

Does anyone know if there's something about a user control that prevents modifying the display this way? I'm testing this on C# Express Edition 2008 on Windows XP.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top