Any of the Words
Link to us
A simple way to make a text box work like a chat w...
Jeremy E. Reed
Click to e-mail author
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.
'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.
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
© 2023 A1VBCode. All rights reserved.