Reputation: 11
I am using Visual Studio Express 2010 with visual basic. I am trying to both learn and test the product enough in 30 days to see if the regular Visual Studio 2010 (Vbasic in particular) will meet my needs. Here's the problem/question. I have an output kind of textbox on a form, textbox1, which is written to programmatically. I have set it to be multiline, enabled, read only, and scrollbar: vertical. I need to fix it so that the scroll thumb moves to the bottom automatically each time the text is overwritten or appended to. (I am overwriting, but actually adding to the textbox (TextBox1.Text & Chr(13) & Chr(10) & newtextdata). The values properties of TextBox1 includes a minimum which is zero and a maximum which is 100. Changing those doesn't seem to help. There is no autoscroll property on a textbox. I even tried setting the textbox to scrollbars: none and then adding from the toolbar a VScrollBar, but I couldn't get it to hook up to TextBox1 and I don't know how to make that one scroll programmatically to the bottom either. Would you please give me the necessary code? Also, if there needs to be a system import, would you please mention that too? This is a make or break feature for me. If this product and vbasic won't do this, then I have to look at something else. I have searched already through three books plus online here and can't figure it out. Thanks so much!
Upvotes: 0
Views: 2568
Reputation: 11
Thanks to the suggestion here (from David), I came up with something that works, and because it wasn’t exactly the same as David’s suggestion, I wanted to share the specifics with you…
First, I added a public sub…
PublicClassForm1 PublicSub ScrollToCaret()
EndSub
Then in an Accept button routine for the user‘s input, I did the following….
OutputTextBox.ScrollToCaret()
OutputTextBox.SelectedText = strTextBeingAdded + _
Microsoft.VisualBasic.vbCrLf
I had a problem, though with the OutputTextBox.Text set on the Design page and had to erase it and put it into the Form load event so that it would scroll to caret there too...
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load OutputTextBox.ScrollToCaret() OutputTextBox.SelectedText = "Initial Description” & strWrap + _ Microsoft.VisualBasic.vbCrLf
Thanks for the comment that led me to this!
Upvotes: 1
Reputation: 2970
Use the SelectionStart property:
TextBox.SelectionStart = Len(TextBox.Text)
Upvotes: 0