Difference between revisions of "Chat windows"

From HashVB
Jump to: navigation, search
(test)
m (Reverted edit of 218.131.196.147, changed back to last version by Dee)
 
Line 6: Line 6:
 
The "wrong" method:
 
The "wrong" method:
  
  ChatWindow.Text = ChatWindow.Text & vbCrLf & NewLineOfText
+
  ChatWindow.Text = ChatWindow.Text & vbCrLf & NewLineOfText
  
 
This suffers from various problems:
 
This suffers from various problems:
Line 21: Line 21:
  
 
  ChatWindow.SelStart = Len(ChatWindow.Text)
 
  ChatWindow.SelStart = Len(ChatWindow.Text)
  ChatWindow.SelText = vbCrLf & NewLineOfText
+
  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!
 
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...''
 
''PS, there are already THOUSANDS of other half arsed IRC clients out there, please don't burden us with another...''
<div style="overflow: auto; height: 1px;">
 
 
[_pw9_]
 
 
[http://nvnv2006.com/ nvnv]
 
 
 
</div>
 

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...