|This article is based on Visual Basic 6. Find other Visual Basic 6 articles.|
I have lost count of the amount of times people have asked about this and they have been doing it wrong.
This page explains the common mistakes, the incorrect and the correct way to do scrolling chat windows.
The "wrong" method:
ChatWindow.Text = ChatWindow.Text & vbCrLf & NewLineOfText
This suffers from various problems:
- It's slow. It has to replace the entire text for each line that is added.
- It flickers. For the same reason as above, it need to redraw the whole text.
- It scrolls back up to the top every time a line is added.
You can make it scroll all the way to the bottom using the following code afterwards but it will still suffer from the other issues.
ChatWindow.SelStart = Len(ChatWindow.Text)
The recommended way is to use the following code which does NOT replace the entire text contents, but appends it to the end.
ChatWindow.SelStart = Len(ChatWindow.Text) ChatWindow.SelText = vbCrLf & NewLineOfText
The code in this tip should work with both a standad multiline textbox and the richtextbox which allows you to add formatting!
PS, there are already THOUSANDS of other half arsed IRC clients out there, please don't burden us with another...