




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、一、設(shè)計(jì)思路用 C#寫的比較基礎(chǔ)的 windows Form 程序 , 該計(jì)算器實(shí)現(xiàn)了基礎(chǔ)的數(shù)學(xué)運(yùn)算 , 如 加 , 減 , 乘 , 除等任務(wù) . 主要是通過該程序?qū)W習(xí) 的編程環(huán)境 , 以及 windows Form程序 . 主要針對(duì)初學(xué)者我們分兩部份來實(shí)現(xiàn)程序 ,第一部份 . 程序界面1, 以下控件表 Double dblAcc; /運(yùn)算數(shù) ADouble dblSec; /運(yùn)算數(shù) Bbool blnClear,blnFrstOpen;/布爾類型用來判斷清除與否 , 以及第一個(gè)顯示字符String strOper;/通過獲取 strOper 的值來決定運(yùn)算 +,-,*,/,=2, 用以下方法
2、來實(shí)現(xiàn)按鈕的動(dòng)作例 : bDot.click+=net EventHandler(btn_clk;/EventHandler類是事件代表類 , 用來 注冊事件的處理方法 ./第一個(gè)參數(shù)是 object 類型 , 指向發(fā)出事件的對(duì)象 ;/第二個(gè)參數(shù)是 EventArgs 類型 , 包含了關(guān)于這個(gè)事件的數(shù)據(jù)3, 用以下方法來判斷運(yùn)算以及運(yùn)算操作private void calc(switch(strOpercase +:dblAcc+=dblSec;/加法運(yùn)算break;case -:dblAcc-=dblSec;/減法運(yùn)算break;case *:dblAcc*=dblSec;/乘法運(yùn)算brea
3、k;case /:dblAcc/=dblSec;/除法運(yùn)算break;strOper=;/等號(hào)運(yùn)算blnFrstOpen=true;txtCalc.Text=Convert.ToString(dblAcc;/將運(yùn)算結(jié)果轉(zhuǎn)換成字符型 , 并輸出結(jié)果dblSec=dblAcc;4, 小數(shù)點(diǎn)運(yùn)算/先判斷是否已經(jīng)按了小數(shù)點(diǎn)按鈕 , 如果按了 , 最 0.x 來代替運(yùn)算變量 , 并且將轉(zhuǎn)換成 Double 數(shù)型數(shù)值 private void btn_clk(object obj,EventArgs eaif(blnCleartxtCalc.Text=;Button b3=(Buttonobj;txtCa
4、lc.Text+=b3.Text;if(txtCalc.Text=.txtCalc.Text=0.;dblSec=Convert.ToDouble(txtCalc.Text;blnClear=false;程序中所涉及到的一些問題 , 都給解決了 , 現(xiàn)在我們動(dòng)手吧 ! 操上我的利器 , 去完成 任務(wù)吧 !名稱用 wincalc, 位置就自己設(shè)定好了。 確定后, 從 開發(fā)環(huán)境中右邊的工具 箱中加入控件表的控件, , 注意修改 txtCalc 的如屬性ReadOnly=True,RightTOLeft=Yes(從右至左輸入 , 最后畫面如何 (pic2添加代碼如源程序所示 :最后大功告成 , 按
5、Ctrl+F5吧 , 看看結(jié)果 .三、源程序/基本的計(jì)算器/蠶蛹 2001.11.26/Using C#/E-mail:sillnetusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace wincalc/ Summary description for calcForm./public class calcForm : System.Windows.Forms.Formprivate System.Wi
6、ndows.Forms.Button button1;private System.Windows.Forms.Button button2;private System.Windows.Forms.Button button3;private System.Windows.Forms.Button button4;private System.Windows.Forms.Button button5;private System.Windows.Forms.Button button6;private System.Windows.Forms.Button button7;private S
7、ystem.Windows.Forms.Button button8;private System.Windows.Forms.Button button9;private System.Windows.Forms.Button button10;private System.Windows.Forms.Button bClr;private System.Windows.Forms.Button bDot;private System.Windows.Forms.Button bPlus;private System.Windows.Forms.Button bSub;private Sys
8、tem.Windows.Forms.Button bMul;private System.Windows.Forms.Button bDiv;private System.Windows.Forms.Button bEqu;private System.Windows.Forms.TextBox txtCalc;/以下是要添加的代碼/定義變量Double dblAcc;Double dblSec;bool blnClear,blnFrstOpen;String strOper;/以上是添加的代碼/ Required designer variable./private System.Compo
9、nentModel.Container components = null;public calcForm(/ Required for Windows Form Designer support/InitializeComponent(;/ TODO: Add any constructor code after InitializeComponent call /以下是要添加的代碼/初始化設(shè)量dblAcc=0;dblSec=0;blnFrstOpen=true;blnClear=true;strOper=new string(=,1;/以上是添加的代碼/ Clean up any reso
10、urces being used./protected override void Dispose( bool disposing if( disposing if(components != nullcomponents.Dispose(;base.Dispose( disposing ;#region Windows Form Designer generated code/ Required method for Designer support - do not modify / the contents of this method with the code editor. /pr
11、ivate void InitializeComponent(this.bPlus = new System.Windows.Forms.Button(; this.bMul = new System.Windows.Forms.Button(; this.bDot = new System.Windows.Forms.Button(; this.txtCalc = new System.Windows.Forms.TextBox(; this.bClr = new System.Windows.Forms.Button(; this.bDiv = new System.Windows.For
12、ms.Button(; this.bSub = new System.Windows.Forms.Button(; this.button8 = new System.Windows.Forms.Button(; this.button9 = new System.Windows.Forms.Button(; this.bEqu = new System.Windows.Forms.Button(; this.button10 = new System.Windows.Forms.Button(; this.button4 = new System.Windows.Forms.Button(;
13、 this.button5 = new System.Windows.Forms.Button(;this.button6 = new System.Windows.Forms.Button(;this.button7 = new System.Windows.Forms.Button(;this.button1 = new System.Windows.Forms.Button(;this.button2 = new System.Windows.Forms.Button(;this.button3 = new System.Windows.Forms.Button(; this.Suspe
14、ndLayout(;/ bPlus/this.bPlus.BackColor = System.Drawing.SystemColors.Control; this.bPlus.ForeColor = System.Drawing.SystemColors.ControlText; this.bPlus.Location = new System.Drawing.Point(208, 112; this.bPlus.Name = bPlus;this.bPlus.Size = new System.Drawing.Size(32, 80; this.bPlus.TabIndex = 1;thi
15、s.bPlus.Text = +;/以下是要添加的代碼bPlus.Click += new System.EventHandler(this.btn_Oper;/以上是添加的代碼/ bMul/this.bMul.Location = new System.Drawing.Point(160, 112; this.bMul.Name = bMul;this.bMul.Size = new System.Drawing.Size(32, 32; this.bMul.TabIndex = 1;this.bMul.Text = *;/以下是要添加的代碼bMul.Click += new System.
16、EventHandler(this.btn_Oper;/以上是添加的代碼/ bDot/this.bDot.ForeColor = System.Drawing.Color.Black; this.bDot.Location = new System.Drawing.Point(112, 208; this.bDot.Name = bDot;this.bDot.Size = new System.Drawing.Size(32, 32; this.bDot.TabIndex = 0;this.bDot.Text = .;/以下是要添加的代碼bDot.Click += new System.Eve
17、ntHandler(this.btn_clk;/以上是添加的代碼/ txtCalc/this.txtCalc.Location = new System.Drawing.Point(16, 24; this.txtCalc.Name = txtCalc;this.txtCalc.ReadOnly = true;this.txtCalc.RightToLeft = System.Windows.Forms.RightToLeft.Yes; this.txtCalc.Size = new System.Drawing.Size(224, 21; this.txtCalc.TabIndex = 2;
18、this.txtCalc.Text = ;/ bClr/this.bClr.BackColor = System.Drawing.SystemColors.Control; this.bClr.ForeColor = System.Drawing.SystemColors.ControlText; this.bClr.Location = new System.Drawing.Point(208, 64; this.bClr.Name = bClr;this.bClr.Size = new System.Drawing.Size(32, 32; this.bClr.TabIndex = 0;t
19、his.bClr.Text = AC;/以下是要添加的代碼bClr.Click += new System.EventHandler(this.btn_clr;/以上是添加的代碼/ bDiv/this.bDiv.Location = new System.Drawing.Point(160, 160; this.bDiv.Name = bDiv;this.bDiv.Size = new System.Drawing.Size(32, 32; this.bDiv.TabIndex = 1;this.bDiv.Text = /;/以下是要添加的代碼bDiv.Click += new System.
20、EventHandler(this.btn_Oper;/以上是添加的代碼/ bSub/this.bSub.Location = new System.Drawing.Point(160, 64; this.bSub.Name = bSub;this.bSub.Size = new System.Drawing.Size(32, 32; this.bSub.TabIndex = 1;this.bSub.Text = -;/以下是要添加的代碼bSub.Click += new System.EventHandler(this.btn_Oper;/以上是添加的代碼/ button8/this.but
21、ton8.Location = new System.Drawing.Point(16, 64; this.button8.Name = button8;this.button8.Size = new System.Drawing.Size(32, 32; this.button8.TabIndex = 0;this.button8.Text = 7;/以下是要添加的代碼button8.Click += new System.EventHandler(this.btn_clk;/以上是添加的代碼/ button9/this.button9.Location = new System.Drawi
22、ng.Point(64, 64; this.button9.Name = button9;this.button9.Size = new System.Drawing.Size(32, 32; this.button9.TabIndex = 0;this.button9.Text = 8;/以下是要添加的代碼button9.Click += new System.EventHandler(this.btn_clk;/以上是添加的代碼/ bEqu/this.bEqu.BackColor = System.Drawing.SystemColors.Control; this.bEqu.ForeCo
23、lor = System.Drawing.SystemColors.ControlText; this.bEqu.Location = new System.Drawing.Point(160, 208; this.bEqu.Name = bEqu;this.bEqu.Size = new System.Drawing.Size(80, 32; this.bEqu.TabIndex = 1;this.bEqu.Text = =;/以下是要添加的代碼bEqu.Click += new System.EventHandler(this.btn_equ;/以上是添加的代碼/ button10/thi
24、s.button10.Location = new System.Drawing.Point(112, 64; this.button10.Name = button10;this.button10.Size = new System.Drawing.Size(32, 32; this.button10.TabIndex = 0;this.button10.Text = 9;/以下是要添加的代碼button10.Click += new System.EventHandler(this.btn_clk;/ button4/this.button4.Location = new System.D
25、rawing.Point(112, 160; this.button4.Name = button4;this.button4.Size = new System.Drawing.Size(32, 32; this.button4.TabIndex = 0;this.button4.Text = 3;/以下是要添加的代碼button4.Click += new System.EventHandler(this.btn_clk; /以上是添加的代碼/ button5/this.button5.Location = new System.Drawing.Point(16, 112; this.bu
26、tton5.Name = button5;this.button5.Size = new System.Drawing.Size(32, 32; this.button5.TabIndex = 0;this.button5.Text = 4;/以下是要添加的代碼button5.Click += new System.EventHandler(this.btn_clk; /以上是添加的代碼/ button6/this.button6.Location = new System.Drawing.Point(64, 112; this.button6.Name = button6;this.butt
27、on6.Size = new System.Drawing.Size(32, 32; this.button6.TabIndex = 0;this.button6.Text = 5;/以下是要添加的代碼button6.Click += new System.EventHandler(this.btn_clk; /以上是添加的代碼/ button7/this.button7.Location = new System.Drawing.Point(112, 112; this.button7.Name = button7;this.button7.Size = new System.Drawing
28、.Size(32, 32; this.button7.TabIndex = 0;this.button7.Text = 6;/以下是要添加的代碼button7.Click += new System.EventHandler(this.btn_clk;/ button1/this.button1.BackColor = System.Drawing.SystemColors.Control; this.button1.ForeColor = System.Drawing.Color.Black; this.button1.Location = new System.Drawing.Point(
29、16, 208; this.button1.Name = button1;this.button1.Size = new System.Drawing.Size(80, 32; this.button1.TabIndex = 0;this.button1.Text = 0;/以下是要添加的代碼button1.Click += new System.EventHandler(this.btn_clk; /以上是添加的代碼/ button2/this.button2.Location = new System.Drawing.Point(16, 160; this.button2.Name = b
30、utton2;this.button2.Size = new System.Drawing.Size(32, 32; this.button2.TabIndex = 0;this.button2.Text = 1;/以下是要添加的代碼button2.Click += new System.EventHandler(this.btn_clk; /以上是添加的代碼/ button3/this.button3.Location = new System.Drawing.Point(64, 160; this.button3.Name = button3;this.button3.Size = new
31、 System.Drawing.Size(32, 32; this.button3.TabIndex = 0;this.button3.Text = 2;/以下是要添加的代碼button3.Click += new System.EventHandler(this.btn_clk; /以上是添加的代碼/ calcForm/this.AutoScaleBaseSize = new System.Drawing.Size(6, 14; this.ClientSize = new System.Drawing.Size(256, 261; this.Controls.AddRange(new System.Windows.Forms.Control this.txtCalc,this.bEqu,this.bDiv, this.bMul, this.bSub, this.bPlus, this.bDot, this.bClr, this.button10, this.button9, this.button8, this.button7, this.button6, this.button5, this.button4, this.button3, this.button2, this.button1; this.Name = calcForm;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 包過培訓(xùn)機(jī)構(gòu)合同范本
- 勞工住宿合同范本
- 辦公用品購置合同范本
- 共享菜園轉(zhuǎn)讓合同范本
- 公司外包收債合同范本
- 健康產(chǎn)業(yè)合同范本
- 農(nóng)村修橋工程合同范本
- 2024年重慶松山醫(yī)院招聘考試真題
- 寫退貨合同范本
- 2024年重慶市永川區(qū)三教鎮(zhèn)招聘公益性崗位人員筆試真題
- 部編版四年級(jí)下冊道德與法治 第4課 買東西的學(xué)問(第2課時(shí)) 教學(xué)課件
- 慢性活動(dòng)性EB病毒課件
- 葡萄胎全面版課件
- 《冷沖壓工藝與模具設(shè)計(jì)》完整版ppt課件全套教程
- 業(yè)務(wù)招待費(fèi)明細(xì)單
- 高效液相色譜法分析(三聚氰胺)原始記錄1
- 典雅中國風(fēng)詩詞大會(huì)古風(fēng)PPT模板
- Part 7 Formal and Informal Styles課件
- 文化差異及跨文化交際試題集
- 油畫人體張東方姑娘的極致美
- 國家開放大學(xué)《建筑工程計(jì)量與計(jì)價(jià)》章節(jié)測試參考答案
評(píng)論
0/150
提交評(píng)論