Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

What is the simplest way to write values to textBox1.text in Form1 from other classes in the same application?

I have a c# windows application with several classes.  The classes are Form1.cs, MyThreads.cs and ServerSockets.cs. The main form is used to present most of the data to the user via textboxes.  The class called 'MyThreads' is instanced in Form1. The MyThreads class spawns a thread that instances the ServerSockets class which does some socket communication.
Everything runs fine except when the 'ServerSockets' class attempts to write to the Form1 textBox1.text property.
I am hoping there is a very simple way to reference this textbox and write values to Form1's textBox from any of the classes in my application. They all share the same namespace but I can not as yet find anything on the net which easily describes how to do this.  

In summary, is there an easy way to set focus to Form1 and easily write to textBoxes in Form1 from any of the other classes in the application?

Any help would be much appreciated!  :)
2 Solutions
If you are spawning a thread in the background and then using the results to update the form elements is using methodInvokes on the main thread, ie., UI thread. I dont think there is any direct easy way of doing this.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now