0

私はすべてを試しましたが、何もうまくいきません。新しいクラスを作成し、そこにすべてのコーディングを設定し、form1.cs からパブリック メソッドを呼び出そうとしましたが、class1 では textbox1 と送信者が赤字で書かれています。

Form1.cs のコード

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    string text;
    double operand_1, operand_2, solution;
    char Operator;

    #region Form Code
    private void Form1_Load(object sender, EventArgs e)
    {
        operand_1 = operand_2 = solution = 0;
        text = "0";
        Operator = '=';
    }
    #endregion

    #region Number Buttons
    private void numbers_Click(object sender, EventArgs e)
    {
        Class1 cls = new Class1();
        cls.Numbers(textBox1.Text);
    }
    #endregion

    #region Operator Buttons
    private void operators_Click(object sender, EventArgs e)
    {
        Class1 cls1 = new Class1();
        cls1.Operations();
    }
    #endregion
}

次に、Class1 のコーディングのコーディングを次に示します。

public class Class1
{
    string text;
    double operand_1, operand_2, solution;
    char Operator;

    public void Numbers(string text)
    {
        Button button = (Button)sender;
        text += button.Text;
        while (text != "0" && text[0] == '0' && text[1] != '.')
            text = text.Substring(1);
        textBox1.Text = text;
        return text;
    }

    public void Operations()
    {
        if (Operator != '=')
        {
            operand_2 = double.Parse(textBox1.Text);

            switch (Operator)
            {
                case '+': solution = operand_1 + operand_2;
                    break;
                case '-': solution = operand_1 - operand_2;
                    break;
                case '*': solution = operand_1 * operand_2;
                    break;
                case '/': solution = operand_1 / operand_2;
                    break;
            }
            Operator = '=';
            textBox1.Text = solution.ToString();
        }
        operand_1 = double.Parse(textBox1.Text);
        Operator = char.Parse(((Button)sender).Text);
        text = "0";
    }
}

送信者エラー: シンボル 'sender' を解決できません テキスト ボックス エラー: シンボル 'textBox1' を解決できません

:'(

どんな助けでもplsをするでしょう!!!

4

2 に答える 2