I have a richtextbox in the form1 and I textbox in the form2 with a text example "hi, have a nice days" so I need to save this text into the richtextbox. So I need code in a button in the form2 for to save the text into the richtextbox in the form1.
Printable View
I have a richtextbox in the form1 and I textbox in the form2 with a text example "hi, have a nice days" so I need to save this text into the richtextbox. So I need code in a button in the form2 for to save the text into the richtextbox in the form1.
I very much doubt that you do need such code. What is the relationship between the two forms? I'm guessing that Form1 creates Form2, correct? Are you displaying the second form modally or non-modally, i.e. with ShowDialog or Show? Do you want to transfer the text back to the first form when the second closes?
I want to use the form two only for populate the richtextbox, for example in the form 1 there is a button "add text" when I make click on this button appear the form two with a textbox so I write or paste a text in this textbox and click ok(other button) for populate the richtextbox.
Is it not simpler to just type directly into the RichTextBox on Form1 rather than open a second Form, type into a TextBox on that Form then have it transferred to the original Form's RichTextBox?
No because I am using a spintax code so I only know work with this with a textbox.
example I have in the textbox something like {hello|hi} {albert|george|lois} have a good {nite|weekend|day}
so each time when I make click the sentence change like :
1-Hello albert have a good nite
2-hi george have a good weekend
etc.
The it is exactly as I thought. The second form shouldn't know anything about the first form. Dialogues should almost always be independent of their caller.
In this case, your OK button on the second form should be setting the form's DialogResult property to OK and that is ALL. You would also add a property (probably a ReadOnly property) that exposes the Text of the TextBox. In the first form, you display the dialogue by calling ShowDialog and then test the result. If it's OK then you get that property value and add it to your RTB.
Thank you very much jmcilhinney