Cursor position in multiline textbox


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();
 
Ad

Advertisements

P

Paul G. Tobey [eMVP]

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.
 

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