1
正如標題所說,我如何清除控件並將窗體重置爲原始狀態?我想這樣做,當我點擊「清除」按鈕時,它會重置所有內容。所以我在下面的代碼中需要一些東西,但是我不知道如何去做,而且我所看到的所有東西都不清楚。清除控件並將窗體重置爲其原始狀態?
private void btnClear_Click(object sender, EventArgs e)
{
}
代碼的其餘部分計算毛支付,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;
}
您似乎在尋找一些不存在的魔法。您清理控件的方式與您填充時完全相同,例如通過設置'ComboBox'的'TextBox'的'Text'和'SelectedIndex','SelectedItem'或'SelectedValue'。請注意''TextBox'也有一個'Clear'方法。 – jmcilhinney