I'm creating a basic C# game but code is not compiling, with the following error
CS0120: An object referenceis required for the non-static field, method or property 'MainMenu.timer1'
This is the code:
try
{
Ping myPing = new Ping();
String host = "www.google.com";
byte[] buffer = new byte[32];
int timeout = 4000;
PingOptions pingOptions = new PingOptions();
PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
}
catch (Exception)
{
MessageBox.Show("You aren't connected a internet or connection is to slow. Please check your connection.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MainMenu.timer1.Enabled = false;
}
Here's the timer1's code:
public void timer1_Tick(object sender, EventArgs e)
{
if (toolStripProgressBar1.Value <= 100)
{
toolStripProgressBar1.Value += 1;
string 123;
123 = label3.Text;
int 1, 2, answ;
sayi1 = Convert.ToInt32(toolStripStatusLabel1.Text);
sayi2 = Convert.ToInt32(123);
answ = 1 + 2;
string ans;
ans = answ.ToString();
toolStripStatusLabel1.Text = ans;
external = ans;
this.Text = "Game (%" + ans + ") - Wait";
}
if (toolStripProgressBar1.Value >= 100)
{
System.Diagnostics.Process.Start(@"bin/MOOperator.exe");
timer1.Stop();
Application.Exit();
}
}
I'm beginner at C# and I don't know much, thanks in advance for solutions.