我无法运行此程序并让它显示我想要的输出

时间:2013-10-16 11:35:11

标签: c# output

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

  

错误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;        
    }
}

1 个答案:

答案 0 :(得分:1)

您不应更改Click Event的委托签名。 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
}