Jared:
Before I posted the last message I built a Windows form to test it. The form
has two textboxes and a button. TextBox txtOutput has its Multiline
property set to True, and its Text property contains a string sufficiently
long so as to overrun the depth of the box. TextBox txtInput is just a
regular textbox that starts with a string about the length of an average
sentence.
Here's the code for the button:
Private Sub btnAppendText_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAppendText.Click
Me.txtOutput.AppendText(Me.txtInput.Text)
Me.txtOutput.ScrollToCaret()
End Sub
Upon clicking that button, txtOutput is scrolled to the bottom of the text,
and the button still has the focus. Same result if you substitute the
statement
Me.txtOutput.SelectionStart = Me.txtOutput.Text.Length
for the ScrollToCaret() line.
Try it, and let me know if you get a different result.
Greg
> Greg,
> As I said before, I too believed this, until 2 MVP's set me strait. If the
[quoted text clipped - 44 lines]
> >> >> textBox1.AppendText(val);
> >> >> textBox1.Select(control.TextLength, 0);
Jared - 24 Sep 2004 11:54 GMT
Greg,
It seems as though the RichTextBox acts differently that a TextBox.
You're right, a textbox doesn't need the focus, try your same routine with a
RichTextBox control. Do you have the same results? Does it scroll?
Jared
> Jared:
>
[quoted text clipped - 84 lines]
>> >> >> textBox1.AppendText(val);
>> >> >> textBox1.Select(control.TextLength, 0);
Greg Dunn - 28 Sep 2004 01:30 GMT
I was still responding to Arkion's original question, which asked how to
make a TextBox (not a RichTextBox) control auto-scroll to bottom after
calling
AppendText. But you're correct, the RichTextBox behaves differently. For
my part, I'd still handle the situation without an unmanaged API call -- I
guess I just don't like them buggers, so if I can avoid them and get what I
want, I do. All you have to do is to set the focus momentarily to the
RichTextBox after appending the text to it, then restore the focus to the
button (or whatever it was) you used to do the append. And of course, the
setting and restoring of the focus could be wrapped neatly in a procedure if
you were doing a lot of this.
Greg
> Greg,
> It seems as though the RichTextBox acts differently that a TextBox.
[quoted text clipped - 90 lines]
> >> >> >> textBox1.AppendText(val);
> >> >> >> textBox1.Select(control.TextLength, 0);