scroll a textbox so bottom-most line always shows

J

Jeremy

I add lines to my textbox (WPF) showing the progress of processes. I'd like
the visible part to scroll so that the most recent line is always visible.
The following does not scroll, but it does refresh. Any ideas?

private void onProgress(string msg)
{
txtProgress.Text += msg + (char)13;
txtProgress.CaretIndex = txtProgress.Text.Length;
oSessionControl.doEvents();
}

doEvents is borrowed code that refreshes the screen.
 
J

Jeremy

Solved. As soon as I finished typing, I saw all those references to scroll
and ....

The answer was

txtProgress.ScrollToLine(txtProgress.LineCount-1);
 
K

Kalpesh

Jeremy,

I haven't worked on WPF.
But I looked at the doc & following could help. Try it

txtProgress.ScrollToLine(txtProgress.LineCount);
or
// if it is a 0 based index
txtProgress.ScrollToLine(txtProgress.LineCount - 1);

Does that work?

Kalpesh
 

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