in c#, I want to send Form1's string's value to appear in Form2's textBox when I click a button of Form1. Can't find a way to do it. can anyone please help???
-
2Please read the FAQ's. This question provides no substance and shows little to no effort on your end. – Botonomous Sep 06 '13 at 20:35
-
2Well what have you tried? Does `Form1` have a reference to the relevant instance of `Form2`? – Jon Skeet Sep 06 '13 at 20:35
2 Answers
I would recommend having a data model layer in your application. The data model would have properties that can be accessed by either Form and would send out events when those properties are changed. When a value is chosen on Form1, it sets the corresponding property on the data model, which then fires an event. Form2 handles that event and is then able to retrieve the new value from the data model. This way, neither form needs to know about the other but the data is still shared.
Hopefully that gets you started. There are plenty of resources available online on how to build an application with a model-view pattern (common implementations are model-view-controller or model-view-viewmodel) and explaining them is beyond the scope of this answer.

- 496
- 4
- 13
You can do it via public properties in Form1 Windows Class.
Then in Form2 use reference to Form1 to get that string from public Property.
I don't know if Form2 has reference to Form1. You gave to little details.

- 28,817
- 29
- 102
- 161
-
`Form2` has no need to access `Form1`, nor should it. The action is happening when `Form1`'s button is clicked. It merely needs to set a property allowing the textbox's text to change. – Servy Sep 06 '13 at 20:41
-
@user2755646 You can always "Accept" the answer so others will find it more easly. – Hooch Sep 14 '13 at 09:58