Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to write in text box and each time i write something i want it to be copied to richtextbox and go to new line then the other statmenet go under the previous one

C#
if (textBox1.Text.Length > 7)
            {
                textBox1.Text = textBox1.Text.Remove(0,7);

            }
            else if (textBox1.Text.Length == 7)
            {
                richTextBox1.Text = textBox1.Text + "\n";
            }


[edit]"Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 20-Apr-11 22:39pm
v2

This is not so trivial if the size is big. (Don't operate with your 7, you can make the interface accepting any append). The common mistake is working with whole text which can be too slow.

You can find correct code compared with incorrect code and explanation in my Solution to this Question:
copy + paste into/ within a rich textbox?[^].

(The only difference with your case: instead of Clipboard text, use you input parameter, the text to be appended.)

—SA
 
Share this answer
 
v2
Comments
Michel [mjbohn] 21-Apr-11 5:00am    
Just out of curiosity: How about using StringBuilder for appending and replacing entire text of richTextBox after each append? Would this also lead to performance issues?
Sergey Alexandrovich Kryukov 21-Apr-11 5:16am    
No. You will need to write whole text each time anyway. There is not "Append" there is only Text and SelectedText, no matter that StringBuilder is in between.

Thank you.
--SA
All you need to do is add a '+' character:
richTextBox1.Text = textBox1.Text + "\n";
Becomes
richTextBox1.Text += textBox1.Text + "\n";
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Apr-11 5:19am    
No. 1) This is not portable (need to use NewLine), 2) too slow in big file. Please see my reference: I explain why even reading textBox.Text is not good; the only way to operate with appended part is TextLength (it does not take Text itself) and SelectedText.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900