In my class “Server.cs”, I want to access a textbox from a form. I tried using this code:
ServerWindow.WriteChatlog(encoder.GetString(message, 0, bytesRead));
But I got this error:
An object reference is required for the non-static field, method, or property 'Chat_Server.ServerWindow.WriteChatlog(string)
ServerWindows.WriteChatlog(string text) looks like this:
public void WriteChatlog(string text)
{
textBox1.Text += text + Environment.NewLine;
}
Now I tried doing that directly from where I was using ServerWindow.WriteChatlog method, but it didn’t work.
They are both non-static
You need to call
WriteChatLogon an instance of theServerWindowclass. Ex: