I want to create a C# code editor by using richtextbox.

I want to provide the code indentation also.

But when i am trying to set the text to aperticular line it is not working. See the code written below.

richtextbox1.Lines[0] = "Hi How r u";

But it is not working. How to assign the text to a perticular line in richtextbox.

Re: Visual C# Express Edition RichtextBox


rtb.Text = "Hello"; //Text on the line cannot be null when selecting

rtb.Select(rtb.GetFirstCharIndexFromLine(0),rtb.Lines[0].Length);//Select the line

rtb.SelectedText = "Hi How r u";//Change the line

rtb.AppendText("\nHello");//Add text to next line

Here's a syntax highlighting textbox:

Re: Visual C# Express Edition RichtextBox

Figo Fei - MSFT

Another solution is to reassign the whole string array to richtextbox1.Lines.

Such as

Code Snippet
richTextBox1.Lines = new string[] {"Hi How r u"};


Code Snippet
string[] lines = richTextBox1.Lines;
lines.SetValue("This is the first line", 0);
richTextBox1.Lines = lines;