正如标题所说,我如何清除控件并将表单重置为原始状态?当我点击按钮"清除"我想是这样的。它会重置一切。所以我在下面的代码中需要一些东西,但我不确定如何去做,我抬起来的一切都不清楚。
private void btnClear_Click(object sender, EventArgs e)
{
}
其余代码会计算grosspay,netpay和其他一些税收减免,并将其显示在表单上。这就是我要在表单上清除/重置的内容。
private void btnCalculatePay_Click(object sender, EventArgs e)
{
double hourlyRate = Convert.ToDouble(txtHourlyRate.Text);
double hoursWorked = Convert.ToDouble(txtHoursWorked.Text);
double grossPay = hourlyRate * hoursWorked;
double stateIncome = grossPay * 0.035;
double federalIncome = grossPay * 0.15;
double socialSecurity = grossPay * 0.062;
double medicare = grossPay * .029;
double netPay = grossPay - (stateIncome + federalIncome + socialSecurity + medicare);
lblDisplay.Text = "Gross Pay: " + grossPay + "\nState Income Tax Deduction: " + stateIncome + "\nFederal Income Tax Deduction: " + federalIncome + "\nSocial Security Deduction: " + socialSecurity + "\nMedicare Deduction: " + medicare + "\nNet Pay: " + netPay;
}
答案 0 :(得分:2)
如果您要清除控制数据,则使用清除控制,您可以使用控件Text
属性并将其设置为string.Empty
,如下所示。同样取决于您在表单中使用的不同控件,并非所有控件都具有Text
属性。
private void btnClear_Click(object sender, EventArgs e)
{
lblDisplay.Text = string.Empty;
txtbox1.Text = string.Empty;
}