First, design ideas
A comparison of the basic Windows Form program written in C #, which implements the basic mathematical operations such as addition, subtraction, multiplication, and other tasks. Mainly through the program to learn Vs.net
Programming environment, and Windows Form programs. Mainly for beginners
We have two parts to implement the program,
The first part. Program Interface
1, the following control table
| control type |
Name |
Text |
| Form |
Calcform |
Calculator |
| button |
Button1 |
0 |
|
..... |
|
|
Button10 |
9 |
|
Bdot |
. (decimal point) decimal point button |
|
Bplus |
+ (plus) plus button |
|
BSub |
-(minus) minus button |
|
Bmul |
* (multiplication) multiplication button |
|
Bdiv |
/(Division) Division Button |
|
Bequ |
= (equal sign) equals button |
|
Bclr |
AC Purge button |
|
Textbox |
Txtcalc (null value) to display input and output results |
Part II, program structure
1, define the following variables
Double dblAcc; //运算数A
Double dblSec; //运算数B
bool blnClear,blnFrstOpen;//布尔类型用来判断清除与否,以及第一个显示字符
String strOper;//通过获取strOper的值来决定运算+,-,*,/,=
2, use the following methods to implement the action of the button
Example: Bdot.click+=net EventHandler (BTN_CLK);//eventhandler class is an event representative class that registers the processing of an event.
The first parameter is the object type, pointing to the objects that emit the event;
The second parameter is the EventArgs type, which contains data about this event
3, use the following methods to determine operations and operations
private void calc(){
switch(strOper){
case "+":
dblAcc+=dblSec;//加法运算
break;
case "-":
dblAcc-=dblSec;//减法运算
break;
case "*":
dblAcc*=dblSec;//乘法运算
break;
case "/":
dblAcc/=dblSec;//除法运算
break;
}
strOper="=";//等号运算
blnFrstOpen=true;
txtCalc.Text=Convert.ToString(dblAcc);//将运算结果转换成字符型,并输出结果
dblSec=dblAcc;
}