[英]clear the controls and reset the form to its original state?
As the title says, how do i clear the controls and reset the form to its original state? 如标题所述,如何清除控件并将表单重置为原始状态? I'm suppose to have it so when I click the button "Clear" it resets everything.
我想拥有它,所以当我单击“清除”按钮时,它将重置所有内容。 So I need something inside the code below, but I'm not sure how to go about it, and everything I looked up wasn't clear.
所以我在下面的代码中需要一些东西,但是我不确定该怎么做,而且我查找的所有内容都不清楚。
private void btnClear_Click(object sender, EventArgs e)
{
}
The rest of the code calculates grosspay, netpay, and a bunch of other tax deductions and display it on the form. 该代码的其余部分将计算总薪水,网络薪水以及其他一系列税收减免,并将其显示在表格上。 So that is what I want to clear/reset on the form.
这就是我要在表单上清除/重置的内容。
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;
}
With clearing control if you mean clearing controls data then you can use controls Text
property and set it to string.Empty
like below. 对于清除控件,如果您要清除控件数据,则可以使用控件的
Text
属性并将其设置为string.Empty
如下所示。 Again depending on the different controls you have in your form and not all controls do have a Text
property. 再次取决于表单中的不同控件,并非所有控件都具有
Text
属性。
private void btnClear_Click(object sender, EventArgs e)
{
lblDisplay.Text = string.Empty;
txtbox1.Text = string.Empty;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.