I have a RichTextBox in a Form that I populate line-by-line (due to formatting, etc.) from my Form_Load function.
While loading, I use GetCharIndexFromPosition function and if the RichTextBox height can accommodates all text lines then the above function always returns the correct CharIndex. If however the RichTextBox height can't accommodate all text lines then for lines past the end of viewable area the GetCharIndexFromPosition returns wrong CharIndex values and i get scrambled text.
As part of trying to resolve the problem I made the Form height (in IDE) fairly small and then in Form_Load function I first changed the height (to accommodate all text lines) and I still get the wrong outcome, i.e. all lines past the original Form size appear wrong. If I then reload the contents, after the form is shown with the new height, then I get the same (bad) result for all lines past the end of viewable are, same as previously. If I bypass that function and always use .TextLength (as I can while loading but not always) then everything is shown properly so I'm sure it's something related to that function that's causing the problem.
Any ideas as to what could be the problem?