Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
A simple way to make a text box work like a chat w...
Author:
Jeremy E. Reed
E-mail:
Click to e-mail author
Submitted:
8/9/2002
Version:
VB6
Compatibility:
VB6
Category:
Controls
Views:
10618
A simple way to make a text box work like a chat window. What I mean is that when a line of text is added, make the line appear at the bottom and the window scoll down. Effectively, the text box will always display the new line added.
Declarations:
'None ' 'To test, create a text box with the following 'properties set: ' 'Multiline = True 'ScrollBars = 3 - Both ' 'For testing purposes, I named the text box txtOut and 'put a command button, Command1, on the form to 'add text to the text box.
Code:
Private Sub Command1_Click() Dim intLen As Integer Static X As Integer 'Get the Length of the text box before the new text 'is added. intLen = Len(txtOut.Text) 'Add the new text to the text box, using X as 'as a counter to show which line is appearing 'on the text box. The X isn't needed, but I 'put it here for demonstration purposes. txtOut.Text = txtOut.Text & vbNewLine & X & "Test" 'Here is the main part, set the selected text 'of the textbox to start on the line after 'the last charecter before the new text was 'added. Then set the Selected text length to 0 'so no text appears highlighted. Done, the new 'line will effictively be displayed as if the 'text box had scrolled down itself. txtOut.SelStart = intLen + 2 txtOut.SelLength = 0 'increase the counter X = X + 1 End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement