時具有誤差我有以下:我創建事件
遊戲類
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)
{
}
}
是它現在沒事了?還是會解僱一些問題,當我運行它(我想拯救自己的調試後..)
操作(+ =)這裏增加了一個事件處理方法到對象的事件。 – 2011-04-13 14:03:48