I have a label with a maximum length of 15 characters, and a multi-line textbox with a max length of basically infinity. I want it to when I type into the textbox to update its text to the label, BUT when the label reaches it's make length to remove the first character and replace the last character with the next letter in the textbox. So basically it looks like a marquee left effect but updates in real time as I type. How would I do this?
This is what I have come up with
private void textBox1_TextChanged(object sender, EventArgs e)
{
String text = textBox1.Text.Replace("\r\n", "|");
int startIndex = ((text.Length - 1) / 15) * 15;
label1.Text = text.Substring(Math.Max(0, startIndex));
}
But it deletes the text after it reached 15 characters and writes again i want it to stream the text as if it were scrolling off to the left.
private void textBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = textBox1.Text.Length <= 15
? textBox1.Text
: new string(textBox1.Text.Skip(textBox1.Text.Length - 15).ToArray());
}
tho if you simply want to fix the code you've got replace this
int startIndex = ((text.Length - 1) / 15) * 15;
with this
int startIndex = text.Length - 15;