The mysterious ways of the RichTextBox...

The kind of systems and applications I normally develop are browser-based, but now and then I try my luck at Windows Forms. Right now I'm doing this little instant messaging program, a pretty simple chat that communicates with a server via SOAP. Anyways, I'm having this battle with a RichTextBox I'm using in a form to display chat messages, smilies and such. Explain this to me: When the RichTextBox is designed to be anchored to the bottom of the form, whenr I add text to it while it's minimized in the task-bar, it refuse to scroll down to the end/bottom of the RichTextBox. The effect is that when I bring up the form from the task-bar and look at it, no messages are displayed until I tap once on the vertical scrollbar! Very amazing and feels like a bug. It doesn't matter how much I try to use the ScrollToCaret() method or other tricks, if the RichTextBox has the anchor property set to bottom, ScrollToCaret() doesn't work as it should.

I think I'll have to subclass the RichTextBox and send my own scroll-messages to it to make this work. :(

2 Comments

  • I believe you need to set focus to the richtextbox first before you call scrolltocaret method:



    textbox.focus

    textbox.selectionstart = textbox.text.length

    textbox.selectionlength = 0

    textbox.scrolltocaret



    Your richtextbox should scroll to bottom properly. But here's the issue: you need to set focus to the control. It will become a problem when you run several applications, say you're working with MS Word. It will always switch to your chat client if it receives a message. This can be quite annoying. It would be much better if you can find the way to auto-scroll without having to first set the focus - something that my limited brain can't figure out how to make it work. If you find the solution, please let me know.

  • Better late than never.



    Simply set the Hide Selection property of the RichTextBox to false.



    neoaez AT earthlink DOT net

Comments have been disabled for this content.