我在toPickedImage方法中收到空引用錯誤,我不明白這是爲什麼。任何人都可以幫助我解釋爲什麼我正在接受這個錯誤。訂閱的事件由於空引用而未觸發
任何和所有的幫助將不勝感激!
代碼如下:
public partial class ownGUI : UserControl
{
private string m_id;
private int m_value;
public event EventHandler<GameEventArgs> Pickedimage;
public ownGUI()
{
InitializeComponent();
}
public ownGUI(String id, int value)
{
InitializeComponent();
m_id = id;
m_value = value;
GameEventArgs image = new GameEventArgs(m_id, m_value);
toPickedimage(image);
}
public void toPickedimage(GameEventArgs e)
{
if (Pickedimage != null)
{
Pickedimage(this, e);
}
}
}
//問候
小觀察:爲什麼在構造函數中引發一個事件?根據定義,沒有調用代碼已經獲得對該對象的引用,所以沒有人可能*在此時訂閱了該事件... – 2013-05-08 08:44:32