private void TxtRate_TextChanged(object sender, EventArgs e) { try { rate = Convert.ToDouble(TxtRate.Text) * 0.01; } catch { //MessageBox.Show("年利率輸入錯誤"); rate = 0; TxtRate.Clear(); TxtRate.Focus(); } Calculation(); }
private void RdbUStoNT_CheckedChanged(object sender, EventArgs e) { if (RdbUStoNT.Checked) { int dollor = 0; double rate = 0; double result = 0; string msg = ""; try { dollor = Convert.ToInt32(TxtDollor.Text); } catch { MessageBox.Show("請輸入金額", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning); RdbUStoNT.Checked = false; TxtDollor.Focus(); return; } try { rate = Convert.ToDouble(TxtRate.Text); } catch { MessageBox.Show("請輸入美金匯率", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning); RdbUStoNT.Checked = false; TxtRate.Focus(); return; } result = dollor * rate; msg = "美金" + dollor.ToString("f2") + "元可兌換成台幣" + result.ToString("f2") + "元"; LblMsg.Text = msg; } }