Difference between revisions of "Chat windows"

From HashVB
Jump to: navigation, search
m (Added VB6 header)
m (Reverted edit of 218.131.196.147, changed back to last version by Dee)
 
(One intermediate revision by one user not shown)
(No difference)

Latest revision as of 13:15, 8 March 2006

float
 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:

  1. It's slow. It has to replace the entire text for each line that is added.
  2. It flickers. For the same reason as above, it need to redraw the whole text.
  3. 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...