C#中 object中无text定义(是否缺少using指令或程序引用)是什么情况?

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 WindowsFormsApp1
{
public partial class Form1 : Form
{
private object textReadout;
private string myNumber;
private string myOperator;
private int num1;
private int result;
private int num2;

    public bool Flag { get; private set; }
    public bool FlagsAttribute { get; private set; }

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        NumClick(0);
    }

    private void button5_Click(object sender, EventArgs e)
    {
        NumClick(3);
    }

    private void button7_Click(object sender, EventArgs e)
    {
        NumClick(4);
    }

    private void button11_Click(object sender, EventArgs e)
    {
        NumClick(1);
    }

    private void button3_Click(object sender, EventArgs e)
    {
        FlagsAttribute = true;
    }

    private void button6_Click(object sender, EventArgs e)
    {
        NumClick(7);
    }

    private void button10_Click(object sender, EventArgs e)
    {
        NumClick(9);
    }

    private void button9_Click(object sender, EventArgs e)
    {
        NumClick(6);
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        textReadout.Text = "0.";
        textReadout.TextAlign = HorizontalAlignment.Right;
    }

    private void textBox1_TextChanged_1(object sender, EventArgs e)
    {
         void NumClick(int myNumber)
        {
            if(Flag)
            {
                txtReadout.Text = txtReadout.Text + myNumber;
            }
            else
            {
                if (textReadout.Text ="0.")
                {
                    textReadout.Text = myNumber + ".";
                }
                else
                {
                    textReadout.Text = txtReadout.Text.Substring(0, txtReadout.Text.Length - 1) + myNumber + ".";
                }
            }
        }

    }

    private void btnNum2_Click(object sender, EventArgs e)
    {
        NumClick(2);
    }

    private void NumClick(int v)
    {
        throw new NotImplementedException();
    }

    private void btnNum5_Click(object sender, EventArgs e)
    {
        NumClick(5);
    }

    private void btnNum8_Click(object sender, EventArgs e)
    {
        NumClick(8);
    }

    private void btnC_Click(object sender, EventArgs e)
    {
        num1 = 0;
        num2 = 0;
        txtReadout.Text = "0.";
        Flag = false; 
    }

    private void btnAdd_Click(object sender, EventArgs e)
    {
        myOperator = "add";
        num1 = double.Parse(txtReadout.Text)
        txtReadout.Text = "0.";
        Flag = false;
    }

    private void btnSub_Click(object sender, EventArgs e)
    {
        myOperator = "Sub";
        num1 = double.Parse(txtReadout.Text);
        txtReadout.Text = "0.";
        Flag = false;

    }

    private void btnMul_Click(object sender, EventArgs e)
    {
        myOperator = "Mul";
        num1 = double.Parse(txtReadout.Text);
        txtReadout.Text = "0.";
        Flag = false;
    }

    private void btnDiv_Click(object sender, EventArgs e)
    {
        myOperator = "Div";
        num1 = double.Parse(txtReadout.Text);
        txtReadout.Text = "0.";
        Flag = false;
    }

    private void btnAmount_Click(object sender, EventArgs e)
    {
        num2=double Parse (txtReadout.Text);
        switch (myOperator)
        {
            case "add":
                result = num1 + num2;
                txtReadout.Text = result.ToString();
                break;
            case "Sub":
                result = num1 - num2;
                txtReadout.Text = result.ToString();
                break;
            case "Mul":
                result = num1 * num2;
                txtReadout.Text = result.ToString();
                break;
            case "Div":
                if(num2=0)
                {
                    textReadout.Text = "除数不能为“0”!";
                }
                else
                {
                    result = num1 / num2;
                    textReadout.Text = result.ToString();
                }
                break;
        }
    }

    private void Parse(string text)
    {
        throw new NotImplementedException();
    }
}

}

1个回答

private object textReadout;
这是什么
你在界面上放一个文本框,叫做 textReadout 就好了,这个去掉

num2=double Parse (txtReadout.Text);
这个double后面少一个点

你可以google下C#的计算器代码,很多现成的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问