The scenario is a long process which logs out progress to a textbox. We repaint the form every iteration (or less). We also want the textbox to be showing the text at the bottom (which is the most recent). Another way would be to insert text at the start of the text box but I think this would be less intuitive for users.
The code is as follows
The textbox must have the focus in order for select to work (according to the documentation - I didn't try it).
The Select procedure moves the caret to the end of the text and scrolltocaret scroll s the box to this position.
Changing the text of the textbox will have invalidated it so calling update will repaint it.
textbox1.Focus;
textbox1.SelectionLength := 0;
textbox1.ScrollToCaret;
textbox1.ScrollToCaret;
Update();
If there are multiple such controls on the form then when each one gets the focus it becomes selected and repaints itself. If you wish to avoid this remove the selection in the "Enter" Event.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment