Cursor positioning in a TextBox

  • Thread starter Thread starter Lilith
  • Start date Start date
L

Lilith

I have a text box I use to update a list of actions as they occur over
a long time. My current method is to accumulate the list string
inside the monitoring function (so I can write it out to file on exit)
and push it out to the text box as the string changes. In essence I'm
shoving a new string with old and new content into the text box. What
I need is for the list string to display it's last line at the bottom
of the text box when the string becomes too large to display within
the confines of the box.

How do I tell the display to do this?
 
Lilith said:
I have a text box I use to update a list of actions as they occur over
a long time. My current method is to accumulate the list string
inside the monitoring function (so I can write it out to file on exit)
and push it out to the text box as the string changes. In essence I'm
shoving a new string with old and new content into the text box. What
I need is for the list string to display it's last line at the bottom
of the text box when the string becomes too large to display within
the confines of the box.

How do I tell the display to do this?

The following should do it after you set the Text property:

textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
 
Lilith said:
[...]
What
I need is for the list string to display it's last line at the bottom
of the text box when the string becomes too large to display within
the confines of the box.

How do I tell the display to do this?

See Select() and ScrollToCaret().
 
I've used two approaches in similar situations.

One approach is to pump the messages to a listbox, adding an item with each
new message. This gives the user the advantage of seeing the steps in the
process. The file is created at the end as a result of all the items added
to the listbox.

The second approach is to have a routine that takes the new message, puts
the message in the text box, and tacks the same message to the end of the
file. I think that just displaying the last string from an array of strings,
or one big string, is just not worth the extra work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top