private static string AdjustText(TextBox textBox, string newText)
{
//replace the new text with the old text if there are already 2 char in the textbox
if (textBox.Text.Length == 2)
{
if (textBox.CaretIndex == 0)
return newText + textBox.Text[1];
else
return textBox.Text[0] + newText;
}
else
{
return textBox.CaretIndex == 0 ?
newText + textBox.Text //if the carrot is in front the text append the new text infront
: textBox.Text + newText; //else put it in behind the existing text
}
}