When I change the SelStart property of my RTF control, I would like the line (depending on the selstart position) to be the first visible line (at the top of the visible part of my RTF).
Is it possible and how can I do that ?
Is there an option in the RTF control or should I use the SendMessage API ?...
Hmm... I don't know if thats possible... not without alot of work anyways. The RichTextbox doesn't divide text up into pages... so you would have to work out how many lines would fit on a page, and then tell it where a new page starts/ends...
I aggre with you when you said that the RichTextbox doesn't divide text up into pages... but what I omitted to tell you is that the file that I load (created by another program) are supposed to fit a specific parameter which is a number of Lines_Per_Page.
I wrote a function GetCharFromLine which call SendMessage API and it works fine when I specified a page number smaller than the current one.
Then, to solve my problem when I specified a page number taller than the current page, I got the idea of setting the cursor (SelStart property) to the 'page specified + 1' then just after, setting the ursor to the 'page specified' and it works fine now !...
' cP is the current page
' nP is the page number that user ask for
z = (((nP + 1) * Lines_Per_Page) - Lines_Per_Page)
x = ((nP * Lines_Per_Page) - Lines_Per_Page)
RTB.SelStart = GetCharFromLine(Text1, x)
'
' if current page is smaller than page number specified
'
If cP < nP Then
RTB.SelStart = GetCharFromLine(Text1, z) ' page + 1
RTB.SelStart = GetCharFromLine(Text1, x) ' page specified
End If
RTB.SelLength = 1 ' just to see where the cursor is
RTB.SetFocus
' returns the first character of line #
Public Function GetCharFromLine(txtbox As RichTextBox, LineIndex As Long) As Long
GetCharFromLine = SendMessage(txtbox.hwnd, EM_LINEINDEX, LineIndex, 0&)
End Function