Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys ,

While converting Turkish char to Latin char...I get a problem..When i do this code in TextChanged event , the cursor on the textBox goes the first line of textBox
How can i overwhelm this problem ? like this picture http://img429.yukle.tc/images/9089first.png[^]


Thanks in advance for your help..



C#
private void txtMesaj_TextChanged_3(object sender, EventArgs e)
      {

              string yazi = txtMesaj.Text;
              yazi = yazi.Replace("ü", "u"); //yazi= yazi.Replace("eski değer","yeni değer") anlamına gelir.Yani yazi değişkenindeki eski değer ile yeni değiştirip tekrardan yazi değişkenime yeni değerimi atıyorum
              yazi = yazi.Replace("ı", "i");
              yazi = yazi.Replace("ö", "o");
              yazi = yazi.Replace("ü", "u");
              yazi = yazi.Replace("ş", "s");
              yazi = yazi.Replace("ğ", "g");
              yazi = yazi.Replace("ç", "c");
              yazi = yazi.Replace("Ü", "U");
              yazi = yazi.Replace("İ", "I");
              yazi = yazi.Replace("Ö", "O");
              yazi = yazi.Replace("Ü", "U");
              yazi = yazi.Replace("Ş", "S");
              yazi = yazi.Replace("Ğ", "G");
              yazi = yazi.Replace("Ç", "C");

              txtMesaj.Text = yazi;
          }
Posted

Save the cursor position at 1st (-> SelectionStart) and set back after all replacements.

C#
int cursorPos = txtMesaj.SelectionStart;

// do something

txtMesaj.SelectionStart = cursorPos; 
 
Share this answer
 
v2
C#
textBox1.SelectionStart = textBox1.TextLength;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900