【问题标题】:No overload for 'button1_Click' matches delegate'button1_Click' 没有重载匹配委托
【发布时间】:2015-02-05 08:18:20
【问题描述】:

我不明白为什么会出现此错误...谁能帮助我?

    private void button1_Click(object sender, EventArgs e, string filePath)
    {
        OpenFileDialog of = new OpenFileDialog();
        of.ShowDialog();
        Filenametext.Text = of.FileName;
        //Create an instance for the openbox dialog
        //And opens the explorer to select the wanted file.

        {

            DataRow row;
            DataService m_WsData = new DataService();


            string XMLFileName = ConfigurationSettings.AppSettings["XMLPath"].ToString() + DateTime.Now.Ticks.ToString() + ".xml";
            FileStream fs = new FileStream(filePath, FileMode.Open);
            StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("ISO-8859-1"));

            {
                DataSet ds = m_WsData.GEDS();


                string line = "";

                int lineNo = 0;
                string lineStart = "";
                string lineEnd = "";
                string[] fileRow;

                {
                    line = sr.ReadLine();
                    if (line != null)
                    {
                        fileRow = line.Split(new Char[] { ';' });

                        if (lineNo == 0)
                        {
                            lineStart = fileRow[0];
                        }
                        if (fileRow[0] != "00" && fileRow[0] != "99")
                        {
                            row = ds.Tables["FuelFileData"].NewRow();
                            row["TransNo"] = fileRow[0];
                            row["CustomerNo"] = fileRow[1];
                            row["TruckNo"] = fileRow[2];
                            row["FuelDate"] = fileRow[3];
                            row["FuelTime"] = fileRow[4];
                            row["Place"] = fileRow[5];
                            row["FuelTypeNo"] = fileRow[6];
                            row["FuelDescription"] = fileRow[7];
                            row["DriverNo"] = fileRow[8];
                            row["Blank"] = fileRow[9];
                            row["TransType"] = fileRow[10];
                            row["Fuel"] = fileRow[11];
                            row["FuelCost"] = fileRow[12];
                            row["MileageFile"] = fileRow[13];
                            row["DrivenKm"] = fileRow[14];
                            row["AverageConsFile"] = fileRow[15];
                            //row["ImportedGuid"]=fileRow[16];


                        }
                        lineEnd = fileRow[0];
                        lineNo++;
                    }
                } while (line != null);

                lineStart = lineStart.Trim() + lineEnd.Trim();

                fs.Close();

                if (lineStart == "0099")
                {
                    ds.WriteXml(XMLFileName);
                    System.IO.File.Delete(XMLFileName);
                }
            }

        }
    }

【问题讨论】:

  • 因为你的文件位置参数,你不能给事件处理程序添加参数
  • string filePath 无法在此处添加,请删除:)

标签: c# button event-handling overloading


【解决方案1】:

原因

您不能在事件处理程序方法上添加参数。 Click 事件定义为

public event RoutedEventHandler Click;

这意味着处理程序必须匹配委托RoutedEventHandler,即

public delegate void RoutedEventHandler(Object sender, RoutedEventArgs e);

解决方案

删除string filePath 参数并通过公共属性传递路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    相关资源
    最近更新 更多