hi guys:)if i have three lines saying "line1","line2"and "line3" and if i want to modify the first line to "line1 ok", the second to "line2 ok " and replace in there original location so i will have "line1 ok",line2 ok" ,"line3" for each line after modification.what should i do to do this.thanks in advance.

You should load the entire contents of the Rich Text Box into an array or list of strings separated by CR/LF, modify them based on your criteria, then overwrite and append all of the text.

The below source will work perfectly. It uses a string array and the richTextBox.Lines property to change each line. It's also using a numeric up down control to choose the line to change. The numeric up down control has a min value of 1 and a max of 65535 in my test app, so that the value will look more realistic to the untrained eye.

// Array holding our information.
        private string[] Lines = new string[65535];

        // The selected line.
        private int SelectedLine = 0;
        
        /// <summary>
        /// Numeric Up Down - Value Changed Event
        /// I'm using this event to select the line I want in my Rich Text Box.
        /// </summary>
        private void ChooseLine(object sender, EventArgs e)
        {
            SelectedLine = Convert.ToInt32(numericUpDown1.Value) - 1;
        }

        /// <summary>
        /// Button - Click Event
        /// I'm using this to change the line I've selected.
        /// </summary>
        private void ChangeLineText(object sender, EventArgs e)
        {
            if (SelectedLine > richTextBox1.Lines.Length)
                MessageBox.Show("Invalid line...");

            else
            {
                Lines = richTextBox1.Lines;
                Lines[SelectedLine] = textBox1.Text;
                richTextBox1.Lines = Lines;
            }
        }

Hope that's what you were wanting. If it answered your post don't forget to mark the thread as solved. :)

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.