0

Hi !!! If any one can help me I'll be pleased! I have one TextBox. I entering some text in the Text Property. After that I pressing the "Enter" button and the cursor position it's going of the next line. I would like to go back the carret at the beggining of the same line where it was. Sorry if my English it's Suck.

Edited by destruct0: n/a

3
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by Momerath
0

To move the cursor to the beginning of the textbox you need to do the following:

textBox1.SelectionStart = 0;
textBox1.SelectionLength = 0;
textBox1.Select();

However, where to do this is the problem.
You can not do it in the TextChanged event as the user might still be typing in the text.:confused:

Edited by nick.crane: n/a

0

First: I need the TextBox to be Multiline and to be true. Second: I use KeyDown Event not TextChanged. And Thank you for your answer but your example isn't work for me.

textBox1.SelectionStart = 0;
textBox1.SelectionLength = 0;
textBox1.Select();

This example, places the carret at the beginning of the second line. I wish the carret to be returned to at the beggining of the first line.

0
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) {
    if (e.KeyChar == (char)Keys.Enter) {
        textBox1.Select(0, 0);
    }
}
0

Thank you for the reply, but this example does not work in my case.
Thanks for your time !!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.