I have a multi-line textbox (let’s call it textBox1) that has plenty of text inside.
After doing a search, I highlight the string I was looking for with:
textBox1.SelectionStart = textBox1.Text.ToLower().IndexOf(STRING);
textBox1.SelectionLength = STRING.Length;
Now when I call the form that contains the textbox it highlights the selected text, but what I would like to do is that the scrollbars would scroll automatically to the highlighted text.
I tried
textBox1.ScrollToCaret();
But didn’t work.
Any ideas?
Thank you.
What event are you firing this from? The
Formprobably isn’t in a state where it can process this. If you call fromForm.Loadit will be too soon. If you call fromForm.Shown, it should work properly.