初识WinForm之自制计算器
本帖最后由 wuaixql 于 2017-12-16 11:55 编辑昨天刚刚学了C#的WinForm窗口程序,就自己尝试去做了一个计算器,先上图
界面是丑了一点,哈哈! 大牛勿喷,代码奉上,喜欢的童鞋可以拿去研究,其实挺简单的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JSQ
{
public partial class Frmjsq : Form
{
public Frmjsq()
{
InitializeComponent();
}
private void btn1_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "1";
}
private void btn2_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "2";
}
private void btn3_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "3";
}
private void btn4_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "4";
}
private void btn5_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "5";
}
private void btn6_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "6";
}
private void btn7_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "7";
}
private void btn8_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "8";
}
private void btn9_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "9";
}
private void btn0_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "0";
}
private void btnjia_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "+";
}
private void btnjian_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "-";
}
private void btncheng_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "*";
}
private void btnchu_Click(object sender, EventArgs e)
{
string n = txtShow.Text;
txtShow.Text = n + "/";
}
private void btndy_Click(object sender, EventArgs e)
{
string nums = txtShow.Text;
int fuhaowz = 0;
if ( nums == '+' ||
nums == '-' ||nums == '*'
|| nums == '/')
{
MessageBox.Show("错误");
txtShow.Text = null;
}
else {
char[] fuhao = { '+', '-', '*', '/' };
for (int i = 0; i < nums.Length; i++)
{
for (int j = 0; j < fuhao.Length; j++)
{
if (fuhao == nums)
{
fuhaowz = i;
break;
}
}
}
char b = nums;
string[]m= nums.Split(b);
double n1 = Double.Parse(m);
double n2 = Double.Parse(m);
switch (b)
{
case '+':
txtShow.Text =( n1 + n2).ToString();
break;
case '-':
txtShow.Text = (n1 - n2).ToString();
break;
case '*':
txtShow.Text = (n1 * n2).ToString();
break;
case '/':
txtShow.Text = (n1 / n2).ToString();
break;
}
}
//for (int i = 0; i < nums.Length; i++)
//{
// else
// {
// if (nums == '+' || nums == '-' || nums == '*' || nums == '/')
// {
// fuhao = nums.ToString();
// }
// else
// {
// if (nums == '+' || nums == '-' || nums == '*' || nums == '/')
// {
// fuhao = nums.ToString();
// }
// }
// }
//}
}
private void btnqc_Click(object sender, EventArgs e)
{
txtShow.Text = null;
}
}
}
不会你举啥手! 发表于 2017-12-16 13:43
能做出个大概就是好样的,楼主继续加油
谢谢,就是还有好多漏洞,目前的我还是无法解决 支持一下孰能生巧 支持一下 加油 ddddddddd 那个大学的 这个是搞IT开发的人用的吧? 能做出个大概就是好样的,楼主继续加油 不错的 很不错 能来点语音吗
页:
[1]
2