Inside my main Form:
partial class Form1 : Form
I have this method:
public void SendLog();
Inside another class: class Player
I have a method which I want to call that SendLog()
from Form1
public void Print()
{
Form1.SendLog(); // Error: An object reference is required for the non-static field, method, or property 'Form1.SendLog(string)'
}
How do I do that ? My Player
class contains many calls to SendLog()
so I prefer to have a global instance of Form1
declared in the beginning so that I can use something like f.SendLog();
rather than passing Form1
instance to method every call.
Like this:
class Player
{
public Form1 f = Form1;
public void Print()
{
f.SendLog();
}
}