1

当我尝试运行我的代码时收到此消息,我知道它不完整。

错误 1 ​​'CalculateGrossPay_Click' 没有重载匹配委托 'System.EventHandler' C:\Users\Jose A Soto\Desktop\Windows Forms Application\Windows Forms Application3\Form1.Designer.cs 169 WindowsFormsApplication3 46

这是我双击错误时显示的代码行:

this.CalculateGrossPay.Click += new System.EventHandler(this.CalculateGrossPay_Click);

我也无法显示任何东西。

public partial class Form1 : Form
{
    private string name;
    //private decimal;
    //private decimal;

    public Form1()
    {
        InitializeComponent();
    }

    private decimal CalculateGrossPay_Click(decimal hours, decimal rate)
    {
        decimal result=0.00m;
        decimal standardHours= 0.00m;
        decimal overtimeHours=0.00m;

        if (hours > 40)
        {               
            overtimeHours = (hours - 40) * ( (rate) * 1.5m);
            standardHours = 40 * rate;

            DisplayOutPut.Text = name+ NameTextBox.Text + ""; 

            DisplayOutPut.Text = "Gross Pay:" + result;
        }
        else
        {
            standardHours = hours * rate;
            DisplayOutPut.Text = "Hours:" + HoursTextBox.Text;
            DisplayOutPut.Text = "Rate:" + RateTextBox.Text;
        }

        result = standardHours + overtimeHours;
        return result;        
    }
}
4

1 回答 1

1

您不应更改 Click 事件的委托签名。此处 Click 事件处理程序需要一个与签名匹配的方法。CalculateGrossPay_Click(Object sender, EventArgs e)

执行以下操作,

private void CalculateGrossPay_Click(Object sender, EventArgs e)
{
    CalculateGrossPay(decimal hrs, decimal rate)      ;
}

public void CalculateGrossPay(decimal hrs, decimal rate)
{
    //write your logic here, if you want to return some value, chnage return type
}
于 2013-10-16T11:38:11.923 回答