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.

Recommended Answers

All 6 Replies

Did you try setting the Multiline property to false.

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:

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.

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

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

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

Works fine when I do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.