I have this event which perform some computations inside it (the "for" ones)
The caret inside textBox1(for each letter I write), is redirected to the
beginning of text after those computations, and thats why I inserted the last line in code provided, to rectify that bug:
textBox1.SelectionStart = textBox1.Text.Length;
[I know that "SelectionStart" is in fact the caret position, but because of the computation, it start as I explained]
Now my problem is: When I want to insert a NEW text in the interior of the text, for each letter I write, the caret goes to the end of the text(because of the last line mentioned). How to write something but caret maintain its position?
Thanks.
Here is the code:
private void textBox1_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < literaRom.Length; i++)
{
if (textBox1.Text.Contains(literaRom[i]))
textBox1.Text = textBox1.Text.Replace(literaRom[i], literaRus[i]);
if (textBox1.Text.Contains(literaRom[i].ToUpper()))
textBox1.Text = textBox1.Text.Replace(literaRom[i].ToUpper(), literaRus[i].ToUpper());
}
for (int i = 0; i < literaKeyComp.Length; i++)
{
if (textBox1.Text.Contains(literaKeyComp[i]))
textBox1.Text = textBox1.Text.Replace(literaKeyComp[i], literaRusComp[i]);
if (textBox1.Text.Contains(literaKeyComp[i].ToUpper()))
textBox1.Text = textBox1.Text.Replace(literaKeyComp[i].ToUpper(), literaRusComp[i].ToUpper());
}
textBox1.SelectionStart = textBox1.Text.Length;
}