Hello there,
I am using the UltraTextEditor to display log messages. I can not figure out, how to scroll to the end after I added a new line. What am I missing?
Any help would be appreciated,
Dennis
Hi Dennis,
You probably need to set the SelectionStart property to position the cursor to the end, just as you would for a TextBox.
Hi Mike,
Having the same problem here.
When trying to set the SelectionStart in runtime, I get an exception "Can't access SelectionStart unless the Editor is in edit mode."
I also tried
ProgressEdit.Select(ProgressEdit.Text.Length, 0); ProgressEdit.ScrollToCaret();
Still no good, all I get is that the text is added to the control but only the first lines are shown. To see the text at the last lines, I need to select the edit box and scroll down manually.
Any ideas?
Thanks,Roy.
Hi Roy,
I'm not sure I understand what you are trying to do here. But the error message is pretty clear. The control has to be in edit mode for SelectionStart or SelectionLength to be changed - so that include calling the Select method.
Make sure the control has focus and before you call this code.
Oh, okay. So that seems like a good way to do it. :)
ScrollToCaret is documented as needing the AlwaysInEditMode property set to true.
I am using the UltraTextEditor in the same way as the original poster, ie in multiline mode to display progress of a task. With AlwaysInEditMode set to true, ScrollToCaret works fine and scrolls to the last line, but without this property, ScrollToCaret seems to be completely ignored.
The control is set as follows:
progressTextEditor.AlwaysInEditMode = TrueprogressTextEditor.Multiline = TrueprogressTextEditor.ReadOnly = TrueprogressTextEditor.Scrollbars = System.Windows.Forms.ScrollBars.BothprogressTextEditor.TabStop = FalseprogressTextEditor.WordWrap = False
Each time a new line is added, I do:
progressTextEditor.SelectionStart = progressTextEditor.TextLengthprogressTextEditor.ScrollToCaret()
Are you suggesting this as a solution? Or as a way to duplicate the problem?
This code seems like it should result in an error, since you cannot set the SelectionStart when the control is not in edit mode.
Try this:
_ultraTextEditor.Editor.ExitEditMode(
true, true);
_ultraTextEditor.SelectionStart = _ultraTextEditor.Text.Length;
_ultraTextEditor.ScrollToCaret();