Solved

Adding text to a textbox and move down along the scrollbar

Posted on 2007-11-25
8
313 Views
Last Modified: 2013-11-26
Hi,

I have a timer which add some text (information) to a textbox, and since the textbox is small, I would like it to automatically scroll the textbox down as text are being added. Is it possible?
0
Comment
Question by:Sharalynn
  • 5
  • 3
8 Comments
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 500 total points
ID: 20346582
You can do this to your multi-line textbox:

TextBox1.AppendText("my text")
TextBox1.ScrollToCaret()
0
 

Author Comment

by:Sharalynn
ID: 20349173
Your code works, but however if I used:

TextBox1.Text &= "asfddf" & vbCrLf,

it will not focus on the textbox, and the caret will always be at the 0 position with text going down and down and the scrollbar getting longer and longer.. Any idea on how to solve that? Otherwise your code works perfectly fine.

What is the difference between the 2 of them anyway?
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 20349423
Hi Sharalynn,

That method causes textbox to loose the focus. To ScrollToCaret work you need to have focus and for that you will need to do this:

        TextBox1.Text &= "asfddf" & vbCrLf
        Dim txtLenght As Integer = Len(TextBox1.Text)
        TextBox1.Select(txtLenght, txtLenght)
        TextBox1.ScrollToCaret()

jpaulino
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 500 total points
ID: 20349429
Just one more thing:

Dim txtLenght As Integer = Len(TextBox1.Text)
TextBox1.Select(txtLenght, txtLenght)

This will put the cursor in the last position on the textbox. If you use simply TextBox1.Select() will select all the text.
0
 

Author Comment

by:Sharalynn
ID: 20349677
Excellent, I understand it totally now. Thank you jpaulino!

But one thing, you said we need to focus it, but since we used Select to go to the end of the line always, does it auto focus for us?
0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 500 total points
ID: 20351031
When you select the control in the last position you will focus him.

Any question more ?
0
 

Author Comment

by:Sharalynn
ID: 20351043
Nope, you have answered all completely, thanks lots!
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 20351131
Glad I could help!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question