Automatic Textbox Scrolling

  • Thread starter Thread starter Peyton Collins
  • Start date Start date
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?
 
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();
 
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
 
Back
Top