I have solve the problem above, this is new source code for TextBox update. I make a recognize to find which text should be replaced and delete them first. This source is for Vietnamese. If u are using other languages, update the RemoveUnicode() with ur alphabet table.
public static char RemoveUnicode(char chr)
{
string text2 = chr.ToString();
string[] arr1 = new string[] { "á", "à", "ả", "ã", "ạ", "â", "ấ", "ầ", "ẩ", "ẫ", "ậ", "ă", "ắ", "ằ", "ẳ", "ẵ", "ặ",
"đ",
"é","è","ẻ","ẽ","ẹ","ê","ế","ề","ể","ễ","ệ",
"í","ì","ỉ","ĩ","ị",
"ó","ò","ỏ","õ","ọ","ô","ố","ồ","ổ","ỗ","ộ","ơ","ớ","ờ","ở","ỡ","ợ",
"ú","ù","ủ","ũ","ụ","ư","ứ","ừ","ử","ữ","ự",
"ý","ỳ","ỷ","ỹ","ỵ",};
string[] arr2 = new string[] { "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a",
"d",
"e","e","e","e","e","e","e","e","e","e","e",
"i","i","i","i","i",
"o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o",
"u","u","u","u","u","u","u","u","u","u","u",
"y","y","y","y","y",};
for (int i = 0; i < arr1.Length; i++)
{
text2 = text2.Replace(arr1[i], arr2[i]);
text2 = text2.Replace(arr1[i].ToUpper(), arr2[i].ToUpper());
}
char res = char.Parse(text2);
return res;
}
/// <summary>
/// Handler for character input event.
/// </summary>
/// <param name="chr">Character typed.</param>
/// <returns>
/// True if handled.
/// </returns>
protected override bool OnChar(char chr)
{
base.OnChar(chr);
if (chr == '\t')
{
return false;
}
if (chr >= (char)230)
{
char chrFind = RemoveUnicode(chr);
//using (StreamWriter writetext = new StreamWriter("D:\\TEMP\\WriteLines.txt", true))
//{
//writetext.WriteLine(Text);
//}
int i;
for (i = mCursorPos; i > 0; i--)
{
//using (StreamWriter writetext = new StreamWriter("D:\\TEMP\\WriteLines.txt", true))
//{
//writetext.WriteLine(Text[i-1]);
//}
char checkChr = Text[i-1];
if (checkChr == ' ')
{
i = mCursorPos+1;
break;
}
char checkChrNormalize = RemoveUnicode(checkChr);
if (chrFind == checkChrNormalize) break;
}
if (i>0&&i<= mCursorPos) {
//using (StreamWriter writetext = new StreamWriter("D:\\TEMP\\WriteLines.txt", true))
//{
//writetext.WriteLine(Text[i-1]+' '+ i.ToString() + ' ' + Text.Length.ToString());
//}
DeleteText(i-1, Text.Length-i+1);
}
// for (int j = i-1; j < Text.Length; j++) OnKeyBackspace(true);
//return false;
}
InsertText(chr.ToString());
return true;
}