Cursor position in multiline textbox

  • Thread starter Thread starter Anders Sahlin
  • Start date Start date
A

Anders Sahlin

Hello!
I use a multiline textbox to display application trace information.
I want to have the cursor at the end of the text in the textbox after
adding text to it, otherwise I cant see the latest trace entries.

Here is the code on how I do it today ( which is not efficient):
(Does anyone have a better idea?):

I would be most grateful for any suggestions.

Sincerly Anders Sahlin


mDbgStringBuilder.Append(inputStr);
mDbgStringBuilder.Append("\r\n");

dbgTxtBox.Text = mDbgString.ToString();

//Added these last lines to get textbox to display last entry

dbgTxtBox.Select((dbgTxtBox.Text.Length - 1),1);

dbgTxtBox.ScrollToCaret();
 
That's as efficient as it's going to get. The EM_SETSEL message, which is
what is being passed to the EDIT control when you set the selection
location, doesn't provide a set-selection-to-the-end option. One of its
parameters has to be the actual position to set (maybe you could pass a
large integer greater than the number of characters in the control, but who
knows if this would work or would continue to work as the OS changes).

Paul T.
 
Back
Top