方法没有重载匹配委托'EventHandler'

时间:2018-06-24 14:37:05

标签: c#

我知道这些类型的问题还有其他答案,但是他们通常会说参数不匹配,但是我相信我的参数匹配,所以我不知道为什么我会遇到上述错误我的taskpagenextbtn_Click。尽管我的参数与taskpagenextbtn.Click函数中的TaskPage行匹配。

public Task_Page(TextBox[] subjectnamearray, List<string> datatablesubjectnamearray, int numofsubjects)
{
    InitializeComponent();
    numoftasks.SelectedIndexChanged += (sender2, e2) => numoftasks_SelectedIndexChanged(sender2, e2,subjectnamearray, datatablesubjectnamearray, numofsubjects);
    taskpagenextbtn.Click += (sender3, e3) => taskpagenextbtn_Click(sender3, e3, numofsubjects);
}
private void taskpagenextbtn_Click(object sender, EventArgs e,int numofsubjects)
{
    Marks_and_Weighting_Table marksandweightingtable = new Marks_and_Weighting_Table(subjectnamearray, datatablesubjectnamearray, numofsubjects);

    TextBox[] subject1tasksarray = new TextBox[] { subjectname1task1weighting, subjectname1task2weighting, subjectname1task3weighting, subjectname1task4weighting, subjectname1task5weighting, subjectname1task6weighting };
    TextBox[] subject2tasksarray = new TextBox[] { subjectname2task1weighting, subjectname2task2weighting, subjectname2task3weighting, subjectname2task4weighting, subjectname2task5weighting, subjectname2task6weighting };
    TextBox[] subject3tasksarray = new TextBox[] { subjectname3task1weighting, subjectname3task2weighting, subjectname3task3weighting, subjectname3task4weighting, subjectname3task5weighting, subjectname3task6weighting };
    TextBox[] subject4tasksarray = new TextBox[] { subjectname4task1weighting, subjectname4task2weighting, subjectname4task3weighting,subjectname4task4weighting, subjectname4task5weighting, subjectname4task6weighting };
    TextBox[] subject5tasksarray = new TextBox[] { subjectname5task1weighting, subjectname5task2weighting, subjectname5task3weighting, subjectname5task4weighting, subjectname5task5weighting, subjectname5task6weighting };
    TextBox[] subject6tasksarray = new TextBox[] { subjectname6task1weighting, subjectname6task2weighting, subjectname6task3weighting, subjectname6task4weighting, subjectname6task5weighting, subjectname6task6weighting };

    int i = 0;
    int numberoftasks = Int32.Parse(numoftasks.Text);

    string myString = numofsubjects.ToString();

    MessageBox.Show(myString);
    if (numofsubjects==2)
    {
        while (i<numberoftasks)
        {
            if (subject1tasksarray[i].Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please fill out all textboxes.", "Error Message");
                /*https://www.codeproject.com/Questions/496674/EmptyplusTextboxplusValidationplusinplusC*/

                return;
            }
            if (subject2tasksarray[i].Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please fill out all textboxes.", "Error Message");
                /*https://www.codeproject.com/Questions/496674/EmptyplusTextboxplusValidationplusinplusC*/

                return;
            }
            i = i + 1;
        }
    }

1 个答案:

答案 0 :(得分:0)

基本上,事件处理程序不允许您传递参数。如果要传递参数,则必须创建一个委托,而不是直接添加事件处理程序。

https://www.codeproject.com/Articles/30458/Delegates-in-VB-NET