Solved

Adding text to a textbox and move down along the scrollbar

Posted on 2007-11-25
8
306 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now