を作成する際に、私は、次ている:私は方法を結ぶiは誤差を有するイベント
ゲームクラス
class Game
{
public event EventHandler GameOver;
public void go()
{
PlayerAliveEventArgs playerAlive = new PlayerAliveEventArgs(Alive);
GameOver(this, playerAlive);
}
}
、私は別のクラスに
public class PlayerAliveEventArgs : EventArgs
{
public bool Alive { get; set; }
public PlayerAliveEventArgs(bool deadOrAlive)
{
Alive = deadOrAlive;
}
}
クラスを有しますイベント...
public void Form_Load()
{
game.GameOver += Form1_GameOverMethod; // it shows the error here.
it says no overload of this method matches System.Eventhandler
}
public void Form1_GameOverMethod(object sender, PlayerAliveEventArgs e)
{
if (!e.Alive)
{
GameTimer.Enabled = false;
gameOver = true;
Refresh();
}
}
エラー次のとおりです。
このコンテキストにはメソッドが存在しません。
なぜですか?
大丈夫私は、次の変更を加えた:
public void Form1_GameOverMethod(object sender, EventArgs e)
{
PlayerAliveEventArgs d = (PlayerAliveEventArgs)e;
if (!d.Alive)
{
}
}
は、それが今で大丈夫でしょうか?私はそれを実行したときか、それはいくつかの問題が発生します(私は後者のデバッグ自分自身を保存したい...)
演算子(+ =)はここにあなたのオブジェクトのイベントにイベントハンドラメソッドを追加することができます。 –