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;using System.IO;namespace Counter{ public partial class Form1 : Form { string NowData = DateTime.Now.ToLongDateString(); string NowTime = DateTime.Now.ToLongTimeString().ToString(); string Q; double NewTB; double QQ; bool Tab1 = true; //判定光标位置,TB_1为TRUE,TB_3为FALSE public Form1() { InitializeComponent(); System.Diagnostics.Trace.Listeners.Clear(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(NowData "-Log.txt")); System.Diagnostics.Trace.AutoFlush = true; } private void Form1_Load(object sender, EventArgs e) { System.Diagnostics.Trace.WriteLine(NowTime "-软件重启"); } public void addNum(string num) { if (TB_1.Text!=""&&TB_2.Text!="") { TB_3.Text = TB_3.Text num.ToString(); } else { TB_1.Text = TB_1.Text num.ToString(); } } private void BT_DEL_MouseDown(object sender, MouseEventArgs e) { if (Tab1) { if (TB_1.TextLength > 0) { TB_1.Text = TB_1.Text.Substring(0, TB_1.Text.Length - 1); } } else { if (TB_3.TextLength > 0) { TB_3.Text = TB_3.Text.Substring(0, TB_3.Text.Length - 1); } } } private void BT_P_Click(object sender, EventArgs e) { if ( Tab1 == true) { if (TB_1.TextLength < 1) { TB_1.Text = "0."; } else if (TB_1.Text.IndexOf(".") <= 0) { addNum("."); } } if (Tab1 == false) { if (TB_3.TextLength < 1) { TB_3.Text = "0."; if (TB_3.Text.IndexOf(".") <= 0) { addNum("."); } } } } private void BT_0_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; TB_1.Text = "0"; } else { addNum("0"); } } private void BT_1_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; TB_1.Text = "1"; } else { addNum("1"); } } private void BT_2_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; TB_1.Text = "2"; } else { addNum("2"); } } private void BT_3_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; // this.TB_1.Focus(); Tab1 = true; TB_1.Text = "3"; } else { addNum("3"); } } private void BT_4_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; TB_1.Text = "4"; } else { addNum("4"); } } private void BT_5_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; TB_1.Text = "5"; } else { addNum("5"); } } private void BT_6_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; TB_1.Text = "6"; } else { addNum("6"); } } private void BT_7_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; TB_1.Text = "7"; } else { addNum("7"); } } private void BT_8_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; TB_1.Text = "8"; } else { addNum("8"); } } private void BT_9_Click(object sender, EventArgs e) { if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_1.Text = ""; TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; addNum("9"); } else { addNum("9"); } } private void toolStripMenuItem1_Click(object sender, EventArgs e) { string dddd = NowData "-Log.txt"; if (File.Exists(dddd)) { System.Diagnostics.Process.Start(NowData "-Log.txt"); } } private void TB_1_KeyPress(object sender, KeyPressEventArgs e) { if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46) e.Handled = true; if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "") { TB_1.Text = ""; TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; } if ((int)e.KeyChar == 46) //小数点 { if (TB_1.Text.Length <= 0) e.Handled = true; //小数点不能在第一位 else if (TB_1.Text.IndexOf(".") >= 0) //包含一个小数点 { e.Handled = true; } } if ((int)e.KeyChar == 48) //数字0 { if (TB_1.Text == "0") //第一个数为0时 { e.Handled = true; } } } private void TB_3_KeyPress(object sender, KeyPressEventArgs e) { if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46) e.Handled = true; if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != ""&& e.Handled == false) { TB_1.Text = ""; TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; this.TB_1.Focus(); Tab1 = true; } if ((int)e.KeyChar == 46) //小数点 { if (TB_3.Text.Length <= 0) e.Handled = true; //小数点不能在第一位 else if (TB_1.Text.IndexOf(".") >= 0) //包含一个小数点 { e.Handled = true; } } if ((int)e.KeyChar == 48) //数字0 { if(TB_3.Text == "0") //第一个数为0时 { e.Handled = true; } } } private void BT_DIV_Click(object sender, EventArgs e) { if (TB_4.Text == "") { TB_2.Text = "÷"; this.TB_3.Focus(); Tab1 = false; } else { TB_1.Text = TB_4.Text; TB_2.Text = ""; TB_3.Text = ""; TB_2.Text = "÷"; this.TB_3.Focus(); Tab1 = false; } } private void BT_MUL_Click(object sender, EventArgs e) { if (TB_4.Text == "") { TB_2.Text = "×"; this.TB_3.Focus(); Tab1 = false; } else { TB_1.Text = TB_4.Text; TB_2.Text = ""; TB_3.Text = ""; TB_2.Text = "×"; this.TB_3.Focus(); Tab1 = false; } } private void BT_MIN_Click(object sender, EventArgs e) { if (TB_4.Text == "") { TB_2.Text = "-"; this.TB_3.Focus(); Tab1 = false; } else { TB_1.Text = TB_4.Text; TB_2.Text = ""; TB_3.Text = ""; TB_2.Text = "-";this.TB_3.Focus(); Tab1 = false; } } private void BT_ADD_Click(object sender, EventArgs e) { if (TB_4.Text == "") { TB_2.Text = " "; this.TB_3.Focus(); Tab1 = false; } else { TB_1.Text = TB_4.Text; TB_2.Text = ""; TB_3.Text = ""; TB_2.Text = " "; this.TB_3.Focus(); Tab1 = false; } } private void BT_CLE_Click(object sender, EventArgs e) { TB_1.Text = ""; TB_2.Text = ""; TB_3.Text = ""; TB_4.Text = ""; TB_5.Text = ""; this.TB_1.Focus(); Tab1 = true; } private void BT_EQ_Click(object sender, EventArgs e) { try { double X1 = Convert.ToDouble(TB_1.Text); double Y1 = Convert.ToDouble(TB_3.Text); Count W1 = new Count(); Count W2 = new Count(X1, Y1); if (TB_2.Text == " ") { double result = W1.Add(W2); TB_4.Text = Convert.ToString(result); this.TB_1.Focus(); Tab1 = true; System.Diagnostics.Trace.WriteLine(NowTime "——" TB_1.TextTB_2.Text TB_3.Text "=" TB_4.Text); } else if (TB_2.Text == "-") { double result = W1.Min(W2); TB_4.Text = Convert.ToString(result); this.TB_1.Focus(); Tab1 = true; System.Diagnostics.Trace.WriteLine(NowTime "——" TB_1.Text TB_2.Text TB_3.Text "=" TB_4.Text); } else if (TB_2.Text == "×") { double result = W1.Mul(W2); TB_4.Text = Convert.ToString(result); this.TB_1.Focus(); Tab1 = true; System.Diagnostics.Trace.WriteLine(NowTime "——" TB_1.Text TB_2.Text TB_3.Text "=" TB_4.Text); } else if (TB_2.Text == "÷") { double result = W1.Div(W2); TB_4.Text = Convert.ToString(result); this.TB_1.Focus(); Tab1 = true; System.Diagnostics.Trace.WriteLine(NowTime "——" TB_1.Text TB_2.Text TB_3.Text "=" TB_4.Text); } else { MessageBox.Show("无算术符"); } } catch(Exception Error) { System.Diagnostics.Trace.WriteLine(NowTime "-" Error.Message); MessageBox.Show("输入有误"); } } private void Form1_KeyDown(object sender, KeyEventArgs e) { Keys KEY = e.KeyCode; switch (KEY) { case Keys.Enter: BT_EQ_Click(sender, e); e.Handled = true; break; case Keys.Add: BT_ADD_Click(sender, e); e.Handled = true; break; case Keys.Subtract: BT_MIN_Click(sender, e); e.Handled = true; break; case Keys.Multiply: BT_MUL_Click(sender, e); e.Handled = true; break; case Keys.Divide: BT_DIV_Click(sender, e); e.Handled = true; break; case Keys.Space: BT_CN_Click(sender, e); e.Handled = true; break; case Keys.ShiftKey: BT_CLE_Click(sender, e); e.Handled = true; break; default: break; } } private void BT_CN_Click(object sender, EventArgs e) { if (TB_4.Text != "") { NewTB = Convert.ToDouble(TB_4.Text); } else if (TB_1.Text != "") { NewTB = Convert.ToDouble(TB_1.Text); } if (NewTB >= 0 && NewTB - (int)NewTB == 0 && NewTB < 100000000) //无小数点 { Q = Convert.ToString(NewTB); if (Q != null) { if (NewTB >= 0 && NewTB < 100000000) { ToCn W1 = new ToCn(); ToCn W2 = new ToCn(Q); string W = W1.Text(W2); TB_5.Text = Convert.ToString(W); System.Diagnostics.Trace.WriteLine(NowTime "-" TB_5.Text); } } } if (NewTB >= 0 && NewTB - (int)NewTB != 0 && NewTB < 100000000) //有小数点 { NewTB = (Int64)(NewTB * 100 0.5); //四舍五入 Q = Convert.ToString(NewTB); if (NewTB >= 0 && NewTB < 100000000) { ToCn W1 = new ToCn(); ToCn W2 = new ToCn(Q); string W = W1.Text2(W2); TB_5.Text = Convert.ToString(W); System.Diagnostics.Trace.WriteLine(NowTime "-" TB_5.Text); } } else if (NewTB < 0) { MessageBox.Show("数值太小"); } else if (NewTB >= 100000000) { MessageBox.Show("数值太大"); } } private void toolStripMenuItem2_Click(object sender, EventArgs e) { new Form2().Show(); } private void TB_5_DoubleClick(object sender, EventArgs e) { if (TB_5.Text != "") { Clipboard.SetText(TB_5.Text.Trim()); } } private void TB_1_MouseClick(object sender, MouseEventArgs e) { this.TB_1.Focus(); Tab1 = true; } private void TB_3_MouseClick(object sender, MouseEventArgs e) { this.TB_3.Focus(); Tab1 = false; } }}
下载智能计算器DEMO(含数字转中文、大写金额)用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论