AfterOpenDocument
事件工作正常,但当我添加第二个事件 BeforeSaveDocument
时,我无法编译代码。
我收到的错误是:
No overload for
QWApp_BeforeSaveDocument
matches delegateQuoteWerks.__Application_BeforeSaveDocumentEventHandler
我对 C# 相当陌生,但我认为这一定是一些疏忽。
QWApp.AfterOpenDocument += new __Application_AfterOpenDocumentEventHandler(QWApp_AfterOpenDocument);
QWApp.BeforeSaveDocument += new __Application_BeforeSaveDocumentEventHandler(QWApp_BeforeSaveDocument);
void QWApp_AfterOpenDocument()
{
string todayDate = DateTime.Now.ToString("MM/dd/yyyy");
QWApp.DocFunctions.SetDocumentHeaderValue("DocDate", todayDate, false);
QWApp.DocFunctions.RefreshDisplay();
}
public void QWApp_BeforeSaveDocument(int iSaveAction, bool bCancel)
{
string todayDate = DateTime.Now.ToString("MM/dd/yyyy");
QWApp.DocFunctions.SetDocumentHeaderValue("DocDate", todayDate, false);
QWApp.DocFunctions.RefreshDisplay();
}
最佳答案
正如编译器所说,__Application_BeforeSaveDocumentEventHandler
委托(delegate)具有与 QWApp_BeforeSaveDocument
不同的参数.
确保两者的参数相同。
如果我猜的话,你应该有 ref bool bCancel
或(不太可能, out bool bCancel
)在 QWApp_BeforeSaveDocument
中。再次检查您的__Application_BeforeSaveDocumentEventHandler
委托(delegate),并使您的函数具有相同的参数。
关于C# EventHandler - 没有重载与委托(delegate)匹配(嗯?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9220365/