scroll a textbox so bottom-most line always shows

  • Thread starter Thread starter Jeremy
  • Start date Start date
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.
 
Solved. As soon as I finished typing, I saw all those references to scroll
and ....

The answer was

txtProgress.ScrollToLine(txtProgress.LineCount-1);
 
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
 
Back
Top