Jump to content
  • Advertisement
Sign in to follow this  
thk123

[web] [Silverlight] Auto-scrolling through a text box

This topic is 3266 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

Hello, if this should be in the .NET forum I apologise, I wasn't sure. I am using Silverlight with C# to create an application. One of the elements is an output window,
 TextBox sudoOutputWindow;
. Throughout the running of the application, lines are added on to the text box:
 sudoOutputWindow.Text += "example line /n"
Anyhow, what I want to be able to do is get the text box to scroll down once the lines reach the bottom of the box so the user can always see the latest line. I couldn't find any function in the TextBox class, so is there some other way?

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure if there's a better way of doing it, but this works for me:

// If there is current text and it does not end in a newline, add one.
if (!string.IsNullOrEmpty(outputWindow.Text) && !outputWindow.Text.EndsWith(Environment.NewLine)) {
outputWindow.Text += Environment.NewLine;
}
// Append the text.
outputWindow.Text += DateTime.Now.ToString();
// Set the selection to the end of the text, zero length.
outputWindow.SelectionLength = 0;
outputWindow.SelectionStart = outputWindow.Text.Length;

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!