清除控件并将表单重置为其原始状态?(clear the controls and reset the form to its original state?)

编程入门 行业动态 更新时间:2024-10-13 12:20:15
清除控件并将表单重置为其原始状态?(clear the controls and reset the form to its original state?)

正如标题所说,我如何清除控件并将表单重置为原始状态? 我想有这样的话当我点击“清除”按钮时它会重置一切。 所以我在下面的代码中需要一些东西,但是我不知道如何去做,我抬起来的一切都不清楚。

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

本文发布于:2023-08-04 20:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1422659.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并将   为其   表单   控件   原始

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!