Writing a custom Grid control and need help coding the scrolling events
-
I am writing a custom Grid and can't figure how to get the scrolling to work. I am trying to call ScrollWindow from CSharp and it doesn't seem to be doing anything. I am not getting any exceptions. Can anyone explain what the expected results should be or tell me what i am doing wrong. Any help would be great!!!! Code: [DllImport("User32.dll")] public extern static bool ScrollWindow(IntPtr hWnd, int nXAmount, int nYAmount, ref RECT rectScrollRegion, ref RECT rectClip); public struct RECT { public int bottom; public int top; public int left; public int right; public RECT(int left, int top, int right, int bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } } /***************/ RECT rect = new Rect(102, 2, 770, 381); bool b = NativeMethods.ScrollWindow(this.Handle, change, 0, ref rect, ref rect);
-
I am writing a custom Grid and can't figure how to get the scrolling to work. I am trying to call ScrollWindow from CSharp and it doesn't seem to be doing anything. I am not getting any exceptions. Can anyone explain what the expected results should be or tell me what i am doing wrong. Any help would be great!!!! Code: [DllImport("User32.dll")] public extern static bool ScrollWindow(IntPtr hWnd, int nXAmount, int nYAmount, ref RECT rectScrollRegion, ref RECT rectClip); public struct RECT { public int bottom; public int top; public int left; public int right; public RECT(int left, int top, int right, int bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } } /***************/ RECT rect = new Rect(102, 2, 770, 381); bool b = NativeMethods.ScrollWindow(this.Handle, change, 0, ref rect, ref rect);
I think you're doing too much work on your own here. Windows Forms provides a ScrollableControl class (as well as Panel and ContainerControl). If you have your control inherit from one of those the scrolling will be taken care of for you, you can set the current position with the AutoScrollPosition property (assuming you have autoscrolling enabled). Now sure off hand what sets the bounds for scroll, my first guess would be something with the AutoScrollMinSize property. HTH, James Sonork ID: 100.11138 - Hasaki
-
I think you're doing too much work on your own here. Windows Forms provides a ScrollableControl class (as well as Panel and ContainerControl). If you have your control inherit from one of those the scrolling will be taken care of for you, you can set the current position with the AutoScrollPosition property (assuming you have autoscrolling enabled). Now sure off hand what sets the bounds for scroll, my first guess would be something with the AutoScrollMinSize property. HTH, James Sonork ID: 100.11138 - Hasaki
Here's a reply I got offline from the original poster, posted here for archival purposes :)
Thanks for the suggestion, but i determined what my
error was. I defined my RECT structure incorrectly so
that when it was being passed from managed to
unmanaged code, it was being marshalled incorrectly.The correct definition of RECT:
[StructLayout(LayoutKind.Explicit)]
public struct RECT
{
[FieldOffset(0)] public int left;
[FieldOffset(4)] public int top;
[FieldOffset(8)] public int right;
[FieldOffset(12)] public int bottom;public RECT(int left, int top, int right, int
bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}Sonork ID: 100.11138 - Hasaki