GetScrollInfo and SetScrollInfo in RichTextBox
Posted on 2004-10-18
I'm trying to write a small JAVA text editor with basic real-time syntax highlighting.
I created a 'SyntaxBox' class and derived it from the RichTextBox control.
Inside the class I implemented a procedure 'Parse' which converts the text in the textbox to the Rich Text Format including the correct syntax color formatting.
I then copy the RTF text to the 'Rtf' property of the RichTextBox control and it shows me a nice and smooth highlighted syntax.
However, every time I update my rich text, the cursor runs to the start of the textbox.
I solved this by remembering the SelectionStart property and resetting it after the update.
BUT, I still have a problem with the scrollbar.
As soon as I start typing, the scrollbar jumps to another value.
I'm trying to read the scrollbar position using the 'GetScrollInfo' procedure in user32.dll (the GetScrollPos procedure doesn't seem to work).
This works great, however, I can't seem to set the scrollbar back to its previous value. (or to any value whatsoever, for that matter)
If I call SetScrollInfo(<params>) and immediately afterwards I call the GetScrollInfo procedure, it shows me the correct value.
However, the scroll position of the textbox is not updated...
So I have a few questions:
1.) am I using the right approach to syntax highlighting?
2.) how come the SetScrollInfo procedure doesn't update my textbox?
Here's some relevant code:
public void SetRTF(string text)
ScrollInfoStruct s=new ScrollInfoStruct();
s.fMask=SIF_POS; //only position
MessageBox.Show("GetScrollInfo error: "+GetLastError().ToString());
MessageBox.Show("SetScrollInfo error: "+GetLastError().ToString());
Thanks in advance...