正如标题所说,我如何清除控件并将表单重置为原始状态? 我想有这样的话当我点击“清除”按钮时它会重置一切。 所以我在下面的代码中需要一些东西,但是我不知道如何去做,我抬起来的一切都不清楚。
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; }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; }最满意答案
如果你想清除控件数据,那么你可以使用控件Text属性并将其设置为string.Empty如下所示。 同样取决于您在表单中具有的不同控件,并非所有控件都具有Text属性。
private void btnClear_Click(object sender, EventArgs e) { lblDisplay.Text = string.Empty; txtbox1.Text = string.Empty; }With clearing control if you mean clearing controls data then you can use controls Text property and set it to string.Empty like below. Again depending on the different controls you have in your form and not all controls do have a Text property.
private void btnClear_Click(object sender, EventArgs e) { lblDisplay.Text = string.Empty; txtbox1.Text = string.Empty; }更多推荐
清除,private,form,grossPay,电脑培训,计算机培训,IT培训"/> <meta name="desc
发布评论