C# EventHandler - 没有重载与委托(delegate)匹配(嗯?)

标签 c# event-handling overloading

AfterOpenDocument 事件工作正常,但当我添加第二个事件 BeforeSaveDocument 时,我无法编译代码。

我收到的错误是:

No overload for QWApp_BeforeSaveDocument matches delegate QuoteWerks.__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/

相关文章:

c# - 声明带或不带括号的类的新实例

c# - 如何使用 C# 修改 .plist 文件?

types - 在 F# 中,具有不同 arity 和返回类型的两个函数可以共享一个名称吗?

C++:如何从我自己的函数中的头文件中调用一个函数(比如 funA()),它的名字也是 funA()?

c# - 从控制台应用程序挂接到来自 ActiveX 库的事件

java - 动态绑定(bind)问题

c# - 如何在 ANTLR4 中获取 IParseTree?

c# - PictureBox 不显示图像

android - 使用 mGLSurfaceView 处理 UI 事件

jquery datepicker onselect 事件处理程序多次