private void button11_Click(object sender, EventArgs e)//小数点按钮
{
num += ".";
this.textBox1.Text += ".";
}
如果连续点几下就会出错,因为字符串型转为数值型,数值没有连续几个小数点的,该如何解决这个问题呢?希望大家帮帮忙,谢谢
{
num += ".";
this.textBox1.Text += ".";
}
如果连续点几下就会出错,因为字符串型转为数值型,数值没有连续几个小数点的,该如何解决这个问题呢?希望大家帮帮忙,谢谢
如果多于一个,就不让输入呗
private void point_Click(object sender, EventArgs e)
{
if (!b)
{
num += ".";//------
textBox1.Text += ".";//------
b = true;
//标记---的地方优点啰嗦,只用+=一次就可以了,等值输入完成了在直接给变量赋值不就得了?为什么非要这么麻烦呢?
}
}
等这个数字输入完的时候(也就是说按下了运算符号的时候)
private void point_Click(object sender, EventArgs e)
{
//计算过程完成后
b = fales;
}基本上就这样吧
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace MDI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.IndexOf(".") < 0)
{
textBox1.Text = textBox1.Text + ".";
}
}
}
}
{
Flag = 5;
SoundPlayer sp = new SoundPlayer();
sp.SoundLocation = @"D:\All Downloads\play\年.wav";
sp.Play();
if (!textio.Text.Contains(".") && !textio.Text.StartsWith("+") && !textio.Text.EndsWith("-") && !textio.Text.StartsWith("X") && !textio.Text.StartsWith("÷") && !textio.Text.StartsWith("."))
{
textio.Text = textio.Text + ".";
}
else if (textio.Text.Contains(".") || textio.Text.Contains("+") || textio.Text.Contains("-") || textio.Text.Contains("X") || textio.Text.Contains("÷") || textio.Text.Contains("."))
{
numb = double.Parse(textio.Text);
}
textio.Focus();
}我想做异常处理,但是计算3+/*(-9)都没实现