Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Writing a custom Grid control and need help coding the scrolling events

Writing a custom Grid control and need help coding the scrolling events

Scheduled Pinned Locked Moved C#
csharpcsshelptutorial
3 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hsd
    wrote on last edited by
    #1

    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);

    J 1 Reply Last reply
    0
    • H hsd

      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);

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • J James T Johnson

        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

        J Offline
        J Offline
        James T Johnson
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups