I have a textbox called textBox1, which multiline property is true. When i insert a statement like:
Code |
its showing like :
Code Code |
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

Lalit MRank #1,186 · 1.5K reputationPosted Nov 18, 2009, 9:21 PM EST
--------------------
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.
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 18, 2009, 9:21 PM EST
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.
Amit ChoudharyRank #145 · 15.8K reputationPosted Nov 19, 2009, 2:50 AM EST
Try this, Textbox1.Text="Hello "+Environment.NewLine for next line