delegate
未将对象引用设置到对象的实例namespace D
{
class A
{
public delegate void Sign_StatusChangeHandler(Sign_StatusChangeEventArgs e);
public event Sign_StatusChangeHandler Sign_StatusChanged;
public void insert()
{
string trno="123445";
int week=1;
Sign_StatusChanged(new Sign_StatusChangeEventArgs(trno,week)); }
}
public class Sign_StatusChangeEventArgs : EventArgs
{
public string Center { get; set; }
public int WeekDay { get; set; }
public Sign_StatusChangeEventArgs(string center, int week)
{
Center = center;
WeekDay = week;
}
}
}
namespace D
{ public partial class StudentClass : DevExpress.XtraEditors.XtraForm
{
public StudentClass()
{
InitializeComponent();
}
A a=new A();
private void StudentClass_Load(object sender, EventArgs e)
{
a.Sign_StatusChanged +=new A.Sign_StatusChangeHandler(sign_Sign_StatusChanged);
}
private void sign_Sign_StatusChanged(Sign_StatusChangeEventArgs e)
{
MessageBox.Show(e.Center);
MessageBox.Show(e.WeekDay);
}
}
}
------解决方案--------------------Sign_StatusChanged没有赋初始值,
------解决方案--------------------insert何时调用的,那时候肯定还没有绑定事件,访问为null
------解决方案--------------------
哪块报这个错误了
你的事件是注册了 但是没有调用啊 你没有调用Clss A的Insert()方法 也就没有调用事件哇
还有就是调用事件的时候
C# code
public void insert()
{
string trno="123445";
int week=1;
if(Sign_StatusChanged!=null)
{
Sign_StatusChanged(new Sign_StatusChangeEventArgs(trno,week));
}
}
整体来说 你的这块比较混乱 没理清楚
}