1

I'm working in C#, Windows Forms application, and have a problem getting scroll position for RichTextBox with large amount of text.

I'm using this code:

  public class POINT
    {
        public  int x;
        public int y;

        public POINT()
        {
        }

        public POINT(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }

SendMessage(this.Handle, EM_GETSCROLLPOS, 0, res)

But, when control contains large amount of text, resulting y offset is incorect because upper 16 bits of Y are always 0.

Is there any way to get scroll position larger than 16 bits?

tlombarovic
  • 11
  • 1
  • 3
  • Take a look [at this](http://www.techtalkz.com/c-c-sharp/68735-richtextbox-scroll-position.html#post293785) – Raj Ranjhan Feb 28 '12 at 22:10
  • 1
    Use GetCharIndexFromPosition() instead. GetLineFromCharIndex() to translate to a line number. – Hans Passant Feb 29 '12 at 03:00
  • 2
    Thanks for replays. @HansPassant - I sucedded to get position with GetPositionFromCharIndex. Namely, this function returns position relative to the contol view, so GetPositionFromCharIndex(0) returns exactly scroll position for the control. – tlombarovic Feb 29 '12 at 14:17

1 Answers1

0

I thought it was about time to case this into an answer

GetPositionFromCharIndex(0)

Retrieves the location within the control at the specified character index

This will get the offset, of the character relative the the control

TheGeneral
  • 79,002
  • 9
  • 103
  • 141