错误 - “方法"没有过载匹配委托'System.EventHandler'? [英] Error - No overload for "method" matches delegate 'System.EventHandler'?

查看:33
本文介绍了错误 - “方法"没有过载匹配委托'System.EventHandler'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private async void submitRequestButton_Click(DateTime dateFormat, DateTime startFormat, DateTime endFormat, EventArgs e)
{
    ParseObject request = new ParseObject("Shifts");
    request["Name"] = ParseUser.CurrentUser.Username;
    request["Shift"] = shiftBox.Text;
    request["Rental"] = rentalBox.Checked;
    request["Location"] = locationBox.Text;
    request["Date"] = dateFormat.ToString("MMMM dd, yyyy");
    request["startTime"] = startFormat.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));
    request["endTime"] = endFormat.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));

    await request.SaveAsync();
}

private DateTime datePicker_ValueChanged(DateTime dateFormat, EventArgs e)
{
    dateFormat = datePicker.Value;

    return dateFormat;
}

private DateTime startTimePicker_ValueChanged(DateTime startFormat, EventArgs e)
{
    startFormat = startTimePicker.Value;

    return startFormat;
}

private DateTime endTimePicker_ValueChanged(DateTime endFormat, EventArgs e)
{
    endFormat = endTimePicker.Value;

    return endFormat;
}

我不明白为什么我会在方法 2、3 和 4 中收到此错误.

I don't understand why I am getting this error for methods 2, 3 and 4.

方法"没有重载匹配委托System.EventHandler"?

No overload for "method" matches delegate 'System.EventHandler'?

如果您需要查看更多代码,请告诉我.我很确定一切都连接正确.

If you need to see more code just let me know. I'm pretty sure everything is hooked up properly.

看起来错误来自:this.datePicker.ValueChanged += new System.EventHandler(this.datePicker_ValueChanged);(其他两种方法也是如此).

It looks like the error is coming from: this.datePicker.ValueChanged += new System.EventHandler(this.datePicker_ValueChanged); (the same goes for the other 2 methods).

请帮忙!我是 C# 新手,所以我不完全明白为什么会发生这个错误.

Please help! I'm new to C# so I don't exactly understand why this error is occurring.

推荐答案

所有事件方法的签名都是错误的.第一个参数应该是一个 object 代表触发事件的控件,返回类型应该是 void.

The signatures on all of your event methods are wrong. The first parameter should be an object representing the control that fired the event, and the return type should be void.

private void datePicker_ValueChanged(object sender, EventArgs e)
{
    // Either cast "sender" to the appropriate type of control,
    //  or just reference the control directly if only one could be subscribed

    datePicker.Value
}

看起来您甚至不需要这些事件.只需在执行时引用其他方法中的控件即可.

It looks like you don't even need these events though. Just reference the controls from within the other method when you execute it.

request["Date"] = datePicker.Value.ToString("MMMM dd, yyyy");
request["startTime"] = startTimePicker.Value.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));
request["endTime"] = endTimePicker.Value.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));

这篇关于错误 - “方法"没有过载匹配委托'System.EventHandler'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆