Public Group

how do you make C# textboxes focused always on the last line?

This topic is 4917 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I type in to the chatbox, but it doesn't scroll to the last line. Instead, it just goes to the top of the chatbox again. The new text cannot be seen this way. I always have to scroll down to see the new text. How do I keep this rich textbox focused on the last line? I looked around the net but had no solutions. Any help is great. Thanks.

Share on other sites
Ok, I don't exactly what you are doing, but I think I know what you mean. It sound s like you are programmatically entering the lines in, so when that happens, it stays at the top unless you do this.
I have made this happen by doing this:

Once I entered the text, I selected the very end of the text of it using [your text box name here].Select([textbox].Text.Length - 1, [textbox].Text.Length - 1), and used [your text box name here].ScrollToCaret().

I will get an example in a minute.

Share on other sites

txtOutput.Select(txtOutput.Text.Length - 1, txtOutput.Text.Length - 1);txtOutput.ScrollToCaret();

This works a little bit, but it goes way too far down on the first enter. I just want the caret to be at the last line of text each time. Aka chatrooms, AIM or MSN Messenger does this while chatting to people.

Share on other sites
Hmm... It doesn't do that to me. This is a textbox right? With multiline and scrollbars enabled?

Share on other sites
Quote:
 Original post by RalphzehunterHmm... It doesn't do that to me. This is a textbox right? With multiline and scrollbars enabled?

Rich textbox, and yeah, both of those are enabled. I think what it's doing is starting at the length + the whole length again, causing a big black/empty space to happen below the text.

Share on other sites
Here's a screenshot of what I mean... you can barely move this scrollbar, and it goes to the top, and this black space isn't there anymore. Press enter, this big black space comes in again. Can you maybe show your code that you use?

Share on other sites
Hmm have you tried simply calling AppendText("") that moves the text cursor thingy to the end before appending text...

Share on other sites
Quote:
 Original post by setaglibHmm have you tried simply calling AppendText("") that moves the text cursor thingy to the end before appending text...

That works for me as well, try that out and see if you get different results.

Share on other sites
It didn't do anything.

Current code:
            txtOutput.Select(txtOutput.Text.Length - 1, txtOutput.Text.Length - 1);            txtOutput.AppendText("");            txtOutput.ScrollToCaret();

Share on other sites
Quote:
 Original post by phil05It didn't do anything. Current code: txtOutput.Select(txtOutput.Text.Length - 1, txtOutput.Text.Length - 1); txtOutput.AppendText(""); txtOutput.ScrollToCaret();

It worked for me when I did not have ScrollToCaret after it, and it did not work when I did have that after that so, you should try it again without ScrollToCaret.

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 19
• Forum Statistics

• Total Topics
632163
• Total Posts
3004519

×