I have a Currency Textbox with a mask. The mask is shown in Textbox as --------.--
Thus, the user type enters the numbers in the mask.
Now the client says that he does not want to type letters from left to right. He wants to print from right to left.
Similar to what we have in the calculator.
Now I tried to change the Textbox property of the righttoleft , but that does not help my reason.
In the end, I was stuck in handling a key event to manually change the position. I can change position, but stuck in completing logic.
This is what my code looks like:
void Textbx_KeyDown(object sender, KeyEventArgs e) { String temp = T.Text; string temp2 = T.Text; int CursorIndex = T.SelectionStart - 1; for (int i = 0; i <= CursorIndex; i++) { if (i == 7) { temp2 = temp2.Insert(i, temp[i + 2].ToString()); temp2 = temp2.Remove(i, 2); //i = i + 2; } else if (CursorIndex == i) { temp2 = temp2.Remove(i, 1); temp2 = temp2.Insert(i, temp[i + 1].ToString()); } else { // T.Text = T.Text.Insert(i + 1, "_"); temp2 = temp2.Insert(i, temp[i + 1].ToString()); temp2 = temp2.Remove(i + 1, 1); } } T.Text = temp2; // T.Text = T.Text.Insert(CursorIndex-1, temp[CursorIndex].ToString()); if (CursorIndex != -1) T.SelectionStart = CursorIndex - 1; }
Is there a better way to do this? If not, how do I need to finish the logic?
source share