計算器編程代碼_第1頁
計算器編程代碼_第2頁
計算器編程代碼_第3頁
計算器編程代碼_第4頁
計算器編程代碼_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、/添加方法public double add(double a,double c) return a+b;其余的你可以自己 寫下就好了都是一樣的只是符號不一樣3個文本框 4個點擊按鈕 分別代表 + - * / 如果點擊的+的按鈕你在+的點擊事件里面 調(diào)用這個方法就好了/添加按鈕+的事件private void btnX_1_Click(object sender, EventArgs e)/textbox3 是等于的值 this.textbox3.text=add(double.parse(this.textbox1.text),double.parse(this.textbox2.text)

2、.tostring();其余的按這個方法寫就好了!private void btnX_1_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = 1; else ttx_show.Text += 1; private void btnX_2_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = 2; else ttx_show.Text += 2; private void btnX_3_Click(o

3、bject sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = 3; else ttx_show.Text += 3; private void btnX_4_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = 4; else ttx_show.Text += 4; private void btnX_5_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00)

4、 ttx_show.Text = 5; else ttx_show.Text += 5; private void btnX_6_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = 6; else ttx_show.Text += 6; private void btnX_7_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = 7; else ttx_show.Text += 7; private

5、 void btnX_8_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = 8; else ttx_show.Text += 8; private void btnX_9_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = 9; else ttx_show.Text += 9; private void btnX_0_Click(object sender, EventArgs e) if (t

6、tx_show.Text = 0.00) ttx_show.Text = 0; else ttx_show.Text += 0; private void btnX_round_Click(object sender, EventArgs e) /小數(shù)點代碼 if (ttx_show.Text = 0.00) ttx_show.Text = 0.; else ttx_show.Text += .; private void btnX_bracket_left_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show

7、.Text = (; else ttx_show.Text += (; private void btnX_bracket_right_Click(object sender, EventArgs e) if (ttx_show.Text = 0.00) ttx_show.Text = ); else ttx_show.Text += ); #region 【退格】 private void btnX_backspace_Click(object sender, EventArgs e) ttx_show.Text = ttx_show.Text.Substring(0, ttx_show.T

8、ext.Length - 1);/退格 #endregion #region 【等號】 private void btnX_equal_Click(object sender, EventArgs e) equal_fangfa(); #endregion #region 【除號】 private void btnX_divided_Click(object sender, EventArgs e) if (ttx_show.Text != 0.00) ttx_show.Text += /; #endregion #region 【乘號】 private void btnX_multiply_

9、Click(object sender, EventArgs e) if (ttx_show.Text != 0.00) ttx_show.Text += *; #endregion #region 【減號】 private void btnX_decrease_Click(object sender, EventArgs e) if (ttx_show.Text != 0.00) ttx_show.Text += -; #endregion #region 【加號】 private void btnX_add_Click(object sender, EventArgs e) if (ttx

10、_show.Text != 0.00) ttx_show.Text += +; #endregion #region 【清零】 private void btnX_CE_Click(object sender, EventArgs e) i = 0; ttx_show.Text = i.ToString(#,#0.00); #endregion #endregion #region 【自定義方法】 private void equal_fangfa() try equal = Evaluator.EvalToDouble(ttx_show.Text);/調(diào)用四則運算類 catch (Excep

11、tion ec) MessageBox.Show(錯誤代碼為: + ec.Message); ttx_show.Text = equal.ToString(); #endregion #region 【鍵盤事件】 private void ttx_show_KeyPress(object sender, KeyPressEventArgs e) if (int)e.KeyChar = (int)Keys.D1) if (ttx_show.Text = 0.00) ttx_show.Text = 1; else ttx_show.Text += 1; if (int)e.KeyChar = (i

12、nt)Keys.D2) if (ttx_show.Text = 0.00) ttx_show.Text = 2; else ttx_show.Text += 2; if (int)e.KeyChar = (int)Keys.D3) if (ttx_show.Text = 0.00) ttx_show.Text = 3; else ttx_show.Text += 3; if (int)e.KeyChar = (int)Keys.D4) if (ttx_show.Text = 0.00) ttx_show.Text = 4; else ttx_show.Text += 4; if (int)e.

13、KeyChar = (int)Keys.D5) if (ttx_show.Text = 0.00) ttx_show.Text = 5; else ttx_show.Text += 5; if (int)e.KeyChar = (int)Keys.D6) if (ttx_show.Text = 0.00) ttx_show.Text = 6; else ttx_show.Text += 6; if (int)e.KeyChar = (int)Keys.D7) if (ttx_show.Text = 0.00) ttx_show.Text = 7; else ttx_show.Text += 7

14、; if (int)e.KeyChar = (int)Keys.D8) if (ttx_show.Text = 0.00) ttx_show.Text = 8; else ttx_show.Text += 8; if (int)e.KeyChar = (int)Keys.D9) if (ttx_show.Text = 0.00) ttx_show.Text = 9; else ttx_show.Text += 9; if (int)e.KeyChar = (int)Keys.D0) if (ttx_show.Text = 0.00) ttx_show.Text = 0; else ttx_sh

15、ow.Text += 0; #region 【小鍵盤數(shù)字鍵】 if (int)e.KeyChar = (int)Keys.NumPad1) if (ttx_show.Text = 0.00) ttx_show.Text = 1; else ttx_show.Text += 1; if (int)e.KeyChar = (int)Keys.NumPad2) if (ttx_show.Text = 0.00) ttx_show.Text = 2; else ttx_show.Text += 2; if (int)e.KeyChar = (int)Keys.NumPad3) if (ttx_show

16、.Text = 0.00) ttx_show.Text = 3; else ttx_show.Text += 3; if (int)e.KeyChar = (int)Keys.NumPad4) if (ttx_show.Text = 0.00) ttx_show.Text = 4; else ttx_show.Text += 4; if (int)e.KeyChar = (int)Keys.NumPad5) if (ttx_show.Text = 0.00) ttx_show.Text = 5; else ttx_show.Text += 5; if (int)e.KeyChar = (int

17、)Keys.NumPad6) if (ttx_show.Text = 0.00) ttx_show.Text = 6; else ttx_show.Text += 6; if (int)e.KeyChar = (int)Keys.NumPad7) if (ttx_show.Text = 0.00) ttx_show.Text = 7; else ttx_show.Text += 7; if (int)e.KeyChar = (int)Keys.NumPad8) if (ttx_show.Text = 0.00) ttx_show.Text = 8; else ttx_show.Text +=

18、8; if (int)e.KeyChar = (int)Keys.NumPad9) if (ttx_show.Text = 0.00) ttx_show.Text = 9; else ttx_show.Text += 9; if (int)e.KeyChar = (int)Keys.NumPad0) if (ttx_show.Text = 0.00) ttx_show.Text = 0; else ttx_show.Text += 0; #endregion #region 【加號】 if (int)e.KeyChar = (int)Keys.Add) if (ttx_show.Text !=

19、 0.00) ttx_show.Text += +; #endregion #region 【減號】 if (int)e.KeyChar = (int)Keys.Subtract) if (ttx_show.Text != 0.00) ttx_show.Text += -; #endregion #region 【乘號】 if (int)e.KeyChar = (int)Keys.Multiply) if (ttx_show.Text != 0.00) ttx_show.Text += *; #endregion #region 【除號】 if (int)e.KeyChar = (int)Ke

20、ys.Divide) if (ttx_show.Text != 0.00) ttx_show.Text += /; #endregion #region 【小數(shù)點】 if (int)e.KeyChar = (int)Keys.Decimal)/這里有問題,按小數(shù)點沒反映 /小數(shù)點代碼 if (ttx_show.Text = 0.00) ttx_show.Text = 0.; else ttx_show.Text += .; #endregion #region 【求結(jié)果-回車】 if (int)e.KeyChar = (int)Keys.Enter) equal_fangfa(); #endr

21、egion #region 【退格鍵】 if (int)e.KeyChar = (int)Keys.Back) ttx_show.Text = ttx_show.Text.Substring(0, ttx_show.Text.Length - 1);/退格 #endregion #region 【清零】 if (int)e.KeyChar = (int)Keys.Escape) i = 0; ttx_show.Text = i.ToString(#,#0.00); #endregion #endregion #region 【菜單-復(fù)制】 private void 復(fù)制CToolStripMe

22、nuItem_Click(object sender, EventArgs e) if (ttx_show.SelectedText != ) Clipboard.SetDataObject(ttx_show.SelectedText); #endregion #region 【菜單-粘貼】 private void 粘貼VToolStripMenuItem_Click(object sender, EventArgs e) /莫看懂,拿來用 IDataObject iData = Clipboard.GetDataObject(); / Determines whether the data

23、 is in a format you can use. if (iData.GetDataPresent(DataFormats.Text) / Yes it is, so display it in a text box. ttx_show.Text = (String)iData.GetData(DataFormats.Text); #endregion 下面是四則混合計算類 class Evaluator public static int EvalToInteger(string statement) string s = EvalToString(statement); return int.Parse(s.ToString(); public static double EvalToDouble(string statement) string s = EvalToString(statement); return double.Parse(s); public static string EvalToString(string statement) object o = EvalToObject(statement); return o.ToString(); public static object EvalToObject(string statement)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論