Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right to left typing in text box?

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?

like image 509
user1331032 Avatar asked Jul 04 '13 04:07

user1331032


People also ask

How do you change text direction in a text box?

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.

How do I fix my typing from right-to-left?

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.

How do I turn on text direction?

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.

How do you position text in a text box?

In the Format Text Box dialog box, click the Text Box tab. In the Vertical alignment box, select Top, Middle, or Bottom. Click OK.


1 Answers

There is a property for that in the textbox:

T.RightToLeft = RightToLeft.Yes
like image 131
SysDragon Avatar answered Oct 23 '22 10:10

SysDragon