I have a form with a multiline textInput. I need to update the content of the textInput from an object outside the form.
How can I achieve this? Should I use events, or perhaps pass the textInput to the outside object’s constructor?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Have a look at the MVP pattern – you could have your form implement an IView interface. Your other object would be the Presenter that would call, for example, IView.UpdateText() when something changes (or have your view subscribe to the presenters events – i prefer the method approach).
This separates your concerns and makes your solution more testable as you can mock up implementations of IView, IPresenter and IModel.
The form should check if
this.InvokeRequired == trueto determine if the incoming request is on the UI thread. If it is not you will need to use a delegate.}