The same thing happens when you execute richTextBox1.Text = "hello"; ?
EDIT: attempt to explain the problem
Not seeing all the code, it's hard for me to know for sure.
But I suppose something made the OnLoad event handler OnLoad called from the first call to InitializeComponent , and then in the second call the RichTextBox was replaced with a new instance, and your text was added to the old instance.
If you post minimal code that still has behavior (including the contents of InitializeComponent ), I can try to figure out the reason.
EDIT 2
Well, when you call InitializeComponent twice, you actually create two instances of all the controls on the Form . So what happened, the first call created one RichTextBox . Then the second call created another RichTextBox in exactly the same place, with the same size. Then you set the text to the second RichTextBox .
The reason you don't see the text is because the first RichTextBox hides the second! To test this, you can add code to change the location of richTextBox1 after you set its text, and then you will see that there are two of them ...
source share