私は、基本的なC#のゲームを作成するが、コードだがエラーCS0120:静的でないフィールド、メソッド、またはプロパティ 'MainMenu.timer1'にオブジェクト参照が必要です。どうすれば修正できますか?
CS0120: An object referenceis required for the non-static field, method or property 'MainMenu.timer1'
このエラーがスローされこれは、コードされています
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();
}
}
注:public static void timer1_Tick(object sender, EventArgs e)
ここでタイマー1のコードは
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;
}
です動作しません。
注:
Program p = new Program; p.timer1();
が
[エラー:「非静的フィールド、メソッド、またはプロパティにオブジェクト参照が必要です...」](http://stackoverflow.com/questions/2505181/error-an-object-reference -is-non-static-field-method-or-propに必要) – Tim
エラーが発生した行はどれですか?その行を含むメソッドが 'static'かどうか質問に関連情報を含めてください。 – David
MainMenu.timer1.Enabled = false; on MainMenu.timer1 –