private void button11_Click(object sender, EventArgs e)//小数点按钮
         {
                num += ".";
                this.textBox1.Text += ".";
        }
如果连续点几下就会出错,因为字符串型转为数值型,数值没有连续几个小数点的,该如何解决这个问题呢?希望大家帮帮忙,谢谢

解决方案 »

  1.   

    那你在小数点按钮的单击事件里,判断下this.textBox1.Text里边的小数点的数量吧
    如果多于一个,就不让输入呗
      

  2.   

    可以找个标志位,标志这个数值有小数点,有小数点的数值点不加到字符串里,否则加进去就可以了,可以用stringbuilder
      

  3.   

            bool b = false;
            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;
            }基本上就这样吧
      

  4.   

    点退格键事件中你判断下TEXTBOX中存在点吗,不存在b=false,存在b=true
      

  5.   

    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 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 + ".";
                }
            }
        }
    }
      

  6.   

    private void btnpoint_Click(object sender, EventArgs e)//make a point
            {
                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)都没实现