locked
right to left in multilane textbox??? RRS feed

  • Question

  • hi

    I want the cursor position to be from right to left in the multiline textbox in C# forms Application

    Friday, October 14, 2011 9:47 AM

Answers

  • Hi srieja,

    Set right to left property to yes,

    textBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
    


    • Proposed as answer by Bob Shen Wednesday, October 19, 2011 6:16 AM
    • Marked as answer by Bob Shen Thursday, October 20, 2011 1:32 AM
    Friday, October 14, 2011 9:57 AM
  • Set the RightToLeft property of the textbox to true. But be sure that you text box contains RTL language characters like Arabic, then only it will make sense.

    If you are developing a multicultured application, you can take support of inbuilt feature called localization

    • Proposed as answer by Ameem Friday, October 14, 2011 9:57 AM
    • Marked as answer by Bob Shen Thursday, October 20, 2011 1:33 AM
    Friday, October 14, 2011 9:57 AM
  • There's no built-in way for you to set that AFAIK, but you can implement the behavior yourself.

    First, add an event handler on KeyPress event in your form's constructor:

    this.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
    

    And then implement the following:

            void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                this.textBox1.Select(0, 0);
            }
    

    This will place the cursor at the side of latest entered charactor.

    How to handle delete and backspace is left for you to implement.

    • Proposed as answer by Bob Shen Wednesday, October 19, 2011 6:16 AM
    • Marked as answer by Bob Shen Thursday, October 20, 2011 1:33 AM
    Friday, October 14, 2011 10:08 AM
    Answerer
  • Hi srieja,

    Welcome to the MSDN forum.

    As far as I know you can realize right to left by
    property. But if you want to start from textBox's bottom,
    it is hard to realize(you need to realize a new control).
    If you want to show a textfile in a textbox and hope
    it start from end then you can use like this:
    textBox1.SelectionStart = textBox1.TextLength;
    Hope it can help you.

    Have a nice day.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Bob Shen Wednesday, October 19, 2011 6:16 AM
    • Marked as answer by Bob Shen Thursday, October 20, 2011 1:33 AM
    Monday, October 17, 2011 8:12 AM

All replies

  • Hi srieja,

    Set right to left property to yes,

    textBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
    


    • Proposed as answer by Bob Shen Wednesday, October 19, 2011 6:16 AM
    • Marked as answer by Bob Shen Thursday, October 20, 2011 1:32 AM
    Friday, October 14, 2011 9:57 AM
  • Set the RightToLeft property of the textbox to true. But be sure that you text box contains RTL language characters like Arabic, then only it will make sense.

    If you are developing a multicultured application, you can take support of inbuilt feature called localization

    • Proposed as answer by Ameem Friday, October 14, 2011 9:57 AM
    • Marked as answer by Bob Shen Thursday, October 20, 2011 1:33 AM
    Friday, October 14, 2011 9:57 AM
  •  Actually i have the following code for creating the textbox with right to left alignment

     

    Textbox txt1 = new Textbox();

    txt.righttoleft = system.windows.forms.righttoleft.yes;

    but i need multiline so i added the following code

    txt1.Multiline =  true;

     

    now the cursor is positioned at the top right corner of the multiline text box.............

     

    but i need bottom right of the cursor position..............

    Friday, October 14, 2011 10:04 AM
  •  Actually i have the following code for creating the textbox with right to left alignment

     

    Textbox txt1 = new Textbox();

    txt.righttoleft = system.windows.forms.righttoleft.yes;

    but i need multiline so i added the following code

    txt1.Multiline =  true;

     

    now the cursor is positioned at the top right corner of the multiline text box.............

     

    but i need bottom right of the cursor position..............
    Friday, October 14, 2011 10:05 AM
  • There's no built-in way for you to set that AFAIK, but you can implement the behavior yourself.

    First, add an event handler on KeyPress event in your form's constructor:

    this.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
    

    And then implement the following:

            void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                this.textBox1.Select(0, 0);
            }
    

    This will place the cursor at the side of latest entered charactor.

    How to handle delete and backspace is left for you to implement.

    • Proposed as answer by Bob Shen Wednesday, October 19, 2011 6:16 AM
    • Marked as answer by Bob Shen Thursday, October 20, 2011 1:33 AM
    Friday, October 14, 2011 10:08 AM
    Answerer
  • Friday, October 14, 2011 10:10 AM
  • Maybe possible for the TextBox in WPF form in the future (seems not implemented in current version so no effect).

    There's no such support in Win32 edit control, so you'll have to create your own if you really need this kind of function.

    Friday, October 14, 2011 10:22 AM
    Answerer
  • Hi srieja,

    Welcome to the MSDN forum.

    As far as I know you can realize right to left by
    property. But if you want to start from textBox's bottom,
    it is hard to realize(you need to realize a new control).
    If you want to show a textfile in a textbox and hope
    it start from end then you can use like this:
    textBox1.SelectionStart = textBox1.TextLength;
    Hope it can help you.

    Have a nice day.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Bob Shen Wednesday, October 19, 2011 6:16 AM
    • Marked as answer by Bob Shen Thursday, October 20, 2011 1:33 AM
    Monday, October 17, 2011 8:12 AM