How to change the form object from another class?

You need to change the value of textbox from another class, but I can't seem to do it. Searching in Google I realized that this can be done using events or by changing the access modifier of the textbox in the properties for the public, and then creating the class in the form object and using it to change the value of textbox that I have failed. Please help solve the problem.

Option 1:

public class ClientObject
{
 public delegate void MethodChatLog(string message);
 public event MethodChatLog writeInChatLog;

...

 public void Process()
{

 Form1 form1 = new Form1();

try
{
 Stream = client.GetStream();

 // Get user name
 userName = GetMessage();
 string message = userName + " has joined the chat.";
 // Send the message about signing in to chat to all connected users
 server.BroadcastMessage(message, Id);
 writeInChatLog(message); // here message should be passed to textbox of the form, but alas
 ...

public partial class Form1 : Form
{
 ClientObject clientObject = new ClientObject();

 static ServerObject server;
 static Thread listenerThread;

 public Form1()
{
InitializeComponent();

try
{
 server = new ServerObject();
 listenerThread = new Thread(new ThreadStart(server.Listen));
 listenerThread.Start(); // start thread
}
 catch (Exception exc)
{
server.Disconnect();
}

 clientObject.writeInChatLog += MessageChatLog;
}

 public void MessageChatLog(string message)
{
 chatLogTB.Text += message + "\r\n";
}
}


Option 2:
...
public void Process()
{
 Form1 form1 = new Form1();

try
{
 Stream = client.GetStream();

 // Get user name
 userName = GetMessage();

 string message = userName + " has joined the chat.";
 server.BroadcastMessage(message, Id);
 form1.chatLogTB.Text += message; // nothing changes
...

Also did the private modifier of the textbox and change the textbox value via the public property, but this does not lead to anything.
July 2nd 19 at 17:51
1 answer
July 2nd 19 at 17:53
Controls need to change only the thread in which they are created, that is, in the main thread!
You can wrap changing the code in delegates Action and pass Control.Invoke() form. Example
Could you give an example, but I do not understand what You mean. - raoul.Lakin commented on July 2nd 19 at 17:56
: An example of the link. We can't from another thread to manage the GUI, it is a rule. So we need to transfer (delegate) the required piece of code in the Invoke method of your form, which will execute it in the context of the main (GUI) thread. - Elna.Volkman92 commented on July 2nd 19 at 17:59
: There are plenty of examples in the network for request "How to update the GUI from another thread in C#". Can you recommend a good video on this topic: https://www.youtube.com/watch?v=D9qcKV4j75U - Elna.Volkman92 commented on July 2nd 19 at 18:02

Find more questions by tags Windows FormsC#