Solved

Adding text to a textbox and move down along the scrollbar

Posted on 2007-11-25
8
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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