Automatic Textbox Scrolling

P

Peyton Collins

My CF application in CE4.2 has a textbox which shows which steps a robot is
executing:

Move 1
Move 2
..
..
Move 98
Move 99
etc.

The way it is now, the display shows only Move 1, Move 2, etc. at the top of
the screen, and you have to scroll down to the bottom to see what the robot
is currently doing. I would like to display the last lines in the textbox
string (in this case Move 98, Move 99) at the bottom of the textbox without
having to scroll manually down to the bottom of the textbox every time the
textbox string is changed.

Is this possible?
 
T

Thore Berntsen

If think this code will do it. You will have to run it after you have added
a line to the textbox.

// Scroll textbox

textBoxLog.SelectionLength = 0;

textBoxLog.SelectionStart = textBoxLog.Text.Length;

textBoxLog.ScrollToCaret();
 
S

Sergey Bogdanov

To append new line with auto scroll down use this code:

string t = "new text to append";

yourTextBox.SelectionStart = yourTextBox.Text.Length;
yourTextBox.SelectionLength = 0;
// yourTextBox.SelectedText
SendMessage(yourTextBoxHWND, EM_REPLACESEL, false, t);

For the reason explanation why you should use SendMessage instead of
SelectedText see Alex Feinman's post:
http://blog.opennetcf.org/afeinman/PermaLink,guid,7e8df78c-a583-4b35-ae5d-02207210ab40.aspx
 

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

Top