0503 C#計算機作業
資管二甲 U1035128 郭璟塘
一 C#程式碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Double value = 0;
String operation = "";
bool operation_pressed = false;
public Form1(){
InitializeComponent();
}
private void button_Click(object sender, EventArgs e){
if ((result.Text == "0") || (operation_pressed))
result.Clear();
operation_pressed = false;
Button b = (Button)sender;
result.Text = result.Text + b.Text;
}
private void button18_Click(object sender, EventArgs e){
result.Text = "0";
}
private void operator_click(object sender, EventArgs e){
Button b = (Button)sender;
operation = b.Text;
value = Double.Parse(result.Text);
operation_pressed = true;
}
private void button10_Click(object sender, EventArgs e){
switch (operation){ //判斷+*/ 計算
case "+":
result.Text = (value + Double.Parse(result.Text)).ToString();
break;
case "-":
result.Text = (value - Double.Parse(result.Text)).ToString();
break;
case "*":
result.Text = (value * Double.Parse(result.Text)).ToString();
break;
case "/":
result.Text = (value / Double.Parse(result.Text)).ToString();
break;
default:
break;
}
operation_pressed = false;
}
private void button17_Click(object sender, EventArgs e){
result.Clear();
value = 0;
}
private void button1_Click(object sender, EventArgs e){
Button b = (Button)sender;
result.Text = result.Text + b.Text;
}
private void button17_Click_1(object sender, EventArgs e){ //一開始畫面顯示0
result.Text = "0";
}
}
}
影片示範