Appending to textbox from another class

Mar 25 2009 6:39 AM
Hello, I am newbie.

I have network listening class (seperate) which used to be console application and used console.writeline for logging its actions. I am trying to adapt it for usage in windows forms application, so I want to replace e.g. console.writeline("Waiting for connections...") with do_log("Waiting for connections...").

do_log(string text) would append the new line to textbox (txt_log) in form. That would be like this:
                if (string.IsNullOrEmpty(this.txt_log.Text))
                    this.txt_log.Text = text;
                else
                    this.txt_log.Text = txt_log.Text + "\n" + text;

But I cant call do_log from that network listening class, because there is error
An object reference is required for the non-static field, method, or property 'Gateway.Root.do_log(string)'
So how can I get that reference? I tried different ways already, e.g. adding the following to the 2nd class:
   public static Root mainForm;
        public static Root MainForm
        {
            get { return mainForm; }
            set { mainForm = value; }
        }
and
Framework.mainForm = this;
in the public Root()

Would appreciate your help! Probably the solution is very simple, but I cannot get it.
Regards.

Answers (1)