|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Textbox won't scrollI have placed a TextBox control on a form, and would like to add text to its contents over time. I would like to have the text scroll upward as new lines are added. The following sub almost does it: Private Sub AddText(strText As String) txtInfo.SelStart = Len(txtInfo.Text) txtInfo.SelText = strText & vbCrLf End Sub The problem is that it does not scroll the text upward. It shows the first lines of text rather than the last. I have searched but every example shows code similar to above. The following properties for the textbox are: Enabled = True Locked = True MaxLength = 0 MultiLine = True ScrollBars = 2 - Vertical I'm using VB6 under WinXP, if that matters. Incidentally, the above code works for a RichTextBox, scrolling it automatically. I'd rather not add another control and another component to my project if I don't have to. Everyone says it works for a regular TextBox, but not for me. What am I missing? Thanks in advance, John.
Show quote
Hide quote
"the_tool_man" <john_ma***@bellsouth.net> wrote in message It works fine here with VB6 under XP+SP2. It scrolls and shows the last news:ab098bd8-cb0a-46e3-a326-7a1c23ce3d2c@y9g2000yqg.googlegroups.com... > Hi all: > > I have placed a TextBox control on a form, and would like to add text > to its contents over time. I would like to have the text scroll > upward as new lines are added. The following sub almost does it: > > Private Sub AddText(strText As String) > > txtInfo.SelStart = Len(txtInfo.Text) > txtInfo.SelText = strText & vbCrLf > > End Sub > > The problem is that it does not scroll the text upward. It shows the > first lines of text rather than the last. I have searched but every > example shows code similar to above. The following properties for the > textbox are: > > Enabled = True > Locked = True > MaxLength = 0 > MultiLine = True > ScrollBars = 2 - Vertical > > I'm using VB6 under WinXP, if that matters. > > Incidentally, the above code works for a RichTextBox, scrolling it > automatically. I'd rather not add another control and another > component to my project if I don't have to. Everyone says it works > for a regular TextBox, but not for me. What am I missing? > > Thanks in advance, > John. line. Try searching your project for other instances of AddText, perhaps you have another one as a public Sub or Function. If all else fails, start a new project, and just use the properties and code that you have posted. On Mar 25, 11:17 pm, "Nobody" <nob***@nobody.com> wrote: You're on the right track. I had all my calls to AddText in the> > It works fine here with VB6 under XP+SP2. It scrolls and shows the last > line. Try searching your project for other instances of AddText, perhaps you > have another one as a public Sub or Function. If all else fails, start a new > project, and just use the properties and code that you have posted.- Hide quoted text - > > - Show quoted text - Form_Load event. When I made a new poject, I put them under a command button Click event, and it worked fine. Changing my project to use a command button fixed it. Regards, John. "the_tool_man" <john_ma***@bellsouth.net> wrote in message Works fine here. Are you sure you aren't becoming confused by the white news:ab098bd8-cb0a-46e3-a326-7a1c23ce3d2c@y9g2000yqg.googlegroups.com... > I would like to have the text scroll upward as new lines are > added. The following sub almost does it: > Private Sub AddText(strText As String) > txtInfo.SelStart = Len(txtInfo.Text) > txtInfo.SelText = strText & vbCrLf > End Sub > The problem is that it does not scroll the text upward. It > shows the first lines of text rather than the last. I have > searched but every example shows code similar to above. space at the bottom of the TextBox? Ideally you should set the height of the TextBox so that its client area is just sufficient to display the desired number of lines of text with no extra white space pixels at the bottom (you can do this either in code or at design time). Also, it is probably not wise to add the CrLf at the end of the newly added text, as you are doing, because this will add a whole line of white space, and if there is already nearly a full line of white space at the bottom (if you haven't set the height as previously explained) then it may look as though there are about two lines of white space. So instead of using txtInfo.SelText = strText & vbCrLf you would be better off using txtInfo.SelText = vbCrLf & strText. Mike |
|||||||||||||||||||||||