Anne1995 2015-11-06 15:04 采纳率: 0%
浏览 1173

求帮助,为什么点了运算或者清除没反应呢

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;

public partial class MainForm1 : Form
{
    public MainForm1()
    {
        InitializeComponent();
    }

    private double n3;
    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (textBox1.Text != null || textBox2.Text != null)
            {
                double n1 = Convert.ToDouble(textBox1.Text);
                double n2 = Convert.ToDouble(textBox2.Text);
                switch (comboBox1.Text)
                {
                    case "+":
                        n3 = n1 + n2;
                        break;
                    case "-":
                        n3 = n1 - n2;
                        break;
                    case "*":
                        n3 = n1 * n2;
                        break;
                    case "/":
                        {
                            if (n2 != 0)
                            {
                                n3 = n1 / n2;
                            }
                            else
                            {
                                textBox2.Text = "操作数2不能为0";
                            }
                        }
                        break;

                }
                textBox3.Text = n3.ToString();
            }
            else
            {
                textBox1.Text = "请输入数字";

            }
        }
        catch { }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        if (textBox1.Text != null || textBox2.Text != null || textBox3.Text != null)
        {
            textBox2.Text = null;
            textBox1.Text = null;
            textBox3.Text = null;
            comboBox1.Text = null;
        }
    }
}

}
图片说明
可以发我邮箱帮助2056234911@qq.com,或者评论,谢谢

  • 写回答

2条回答 默认 最新

  • Meditator_hkx 2015-11-06 16:01
    关注

    我只在C中写过MFC程序,也用过java swing,针对这种问题,出现状况的恐怕是在
    textBox3.Text = n3.ToString();
    这个语句或者是与其相关的语句了。

    关键的就是把计算结果赋值给textBox3内容并且**显示出来
    题主你不妨调试一下,看看到这个语句textBox有啥变化没有,判断是赋值还是显示出问题了。
    然后可以再查查显示函数的使用~
    我不太懂C#,只能帮这么多了。

    评论

报告相同问题?

悬赏问题

  • ¥15 vue2中使用计算属性
  • ¥50 远程桌面打开Mastercam、没有许可证、物理机打开正常
  • ¥15 ubuntu安装gdal后java读取tif文件报错
  • ¥15 请问lammps怎么做两种金属连接的原子浓度分布图
  • ¥15 求jacquard数据集
  • ¥15 w10部分软件不能联网
  • ¥15 关于安装hbase的问题(操作系统-windows)
  • ¥15 novnc连接pve虚拟机报错安全协议不支持262
  • ¥15 设备精度0.03给多少公差能达到CPK1.33
  • ¥15 qt+ffmpeg报错non-existing PPS 0 referenced