I have a textbox called textBox1, which multiline property is true. When i insert a statement like:
|
its showing like :
|
But after that i want to set the cursor position on the third line. How to do that. I am using windows applicatio with C#.
regards,
bjb
Amit ChoudharyPosted Nov 19, 2009, 7:50 AM
Try this, Textbox1.Text="Hello "+Environment.NewLine for next line
Nilanka DharmadasaPosted Nov 19, 2009, 2:21 AM
Change your code as follows.
textBox2.Text = "Hello\r\nWorld" + "\n";
this.ActiveControl = textBox2;//This line is optional. You can remove this line if you want.
If you find any problem in this, let me know.
If you find this answer useful, mark this ans accepted.
Lalit MPosted Nov 19, 2009, 2:21 AM
--------------------
The TextBox object contains an Array of strings that make up its multiple lines. To do what would normally look like just a “line feed†or carriage return you must lay it out line by line. Here is the code to do what the first tip does.
string[] newLines = new string[2];
newLines[0]="First line";
newLines[1]="Second line";
TextBox1.Lines= newLines;
Notes:-
--------
Always forget this one - to put a new line in a .Net textbox in C#, use the "\r\n" string (after you've set the textbox to multiline of course). "\t" is tab but that is easy to remember.