I have a Currency Textbox
with a mask.
Mask is shown in textbox
as --------.--
So user types in digits over the mask.
Now customer says he does not want to type in letter from left to right. He wants to type from right to left.
Similar to what we have in calculator.
Now I tried changing the textbox
's righttoleft
property but that does not help my cause.
In the end I am stuck with handling the key event to manually change the position. I am able to change the position but getting stuck completing the logic.
Here's how 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 should I go about completing the logic?
Specify text direction in a shape, text box, or table cell. Enter the text in the shape or text box or table cell, and then select the text. Ctrl+Click the selected text, and then select Format Shape. On the Text Box tab in the dialog box, choose a direction from the Text Direction box.
In most Windows programs (including MS Word, Internet Explorer, and Notepad), you can use the following shortcuts to switch direction: For right-to-left, press: Ctrl + Right. Shift. For left-to-right, press: Ctrl + Left.
Select the text box, and then go to Shape Format or Drawing Tools Format > Rotate. Use any of the rotate commands in the list. Manually rotate the text box by selecting the text box rotation handle and dragging in the direction you want.
In the Format Text Box dialog box, click the Text Box tab. In the Vertical alignment box, select Top, Middle, or Bottom. Click OK.
There is a property for that in the textbox:
T.RightToLeft = RightToLeft.Yes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With