Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing first line text in a RichTextBox 1

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
Suppose I have a TextBox component and a RichTextBox component on a form.
When I click a button I want the text in the TextBox component to be fed into the RichTextBox component first line. I'm using code as follows :

string str1 = textBox1.Text;
richTextBox1.Lines[0] = str1;

Unfortunately this code does not do the trick !
The text in the RichTextBox remains unchanged.
How can I pull this off ?

Thanks in advance
Steve
 
I'm not sure if you want to replace the first line or insert to the first line..

For inserting
Code:
richTextBox1.Text = textBox1.Text + "\n" + richTextBox1.Text

For removing and replacing
Code:
//Make sure to check if box is empty
richTextBox1.Text = richTextBox1.Text.Remove(0,richTextBox1.Lines[0].Length);
richTextBox1.Text = textBox1.Text + richTextBox1.Text;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top