Jump to content
  • Advertisement
Sign in to follow this  
phil05

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Ralphzehunter
Hmm... 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 this post


Link to post
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 this post


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

Share this post


Link to post
Share on other sites
Quote:
Original post by setaglib
Hmm 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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by phil05
It 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!