一、显示界面Form1.cs
1.定义一个button,一个progressbar
private void button_Click(object sender, System.EventArgs e)
{
LawSystem lawSystem = new LawSystem();
lawSystem.onSendMsg += new LawSystem.MyEventHandler(this.OnSendMsg);
bool flag = lawSystem.ImpLawType(alLawTypeID,fileName);
}
//处理 onSendMsg 事件代码
protected void OnSendMsg(int lawTypeNum, int itemCount, int itemNum)
{
this.progressBar1.Value = lawTypeNum;
}
二、界面封装类BusinessFacade.LawSystem.cs
//定义事件
public delegate void MyEventHandler(int libNum, int itemCount, int itemNum);
public event MyEventHandler onSendMsg;
//导入
public bool ImpLawType(IList alLawTypeID,string fileName)
{
LawType lawType = new LawType();
lawType.onSendMsg += new LawType.MyEventHandler(this.OnSendMsg);
return lawType.ImpLawType(alLawTypeID,fileName);
}
//处理 onSendMsg 事件代码
protected void OnSendMsg(int lawTypeNum, int itemCount, int itemNum)
{
//输出调试信息
onSendMsg(lawTypeNum, itemCount, itemNum);
}
三、业务逻辑类BusinessRules.LawType.cs
//定义事件
public delegate void MyEventHandler(int libNum, int itemCount, int itemNum);
public event MyEventHandler onSendMsg;
执行并赋值
onSendMsg(++lawTypeNum,0,0);
转载于:https://www.cnblogs.com/liuzhixian/articles/863621.html