首页 文章

Visual C#错误:System.Windows.Forms.Button不包含ToInt32的定义

提问于
浏览
0

我正在 decimalbinary converter 工作,在控制台上完美运行,然后我得到关于我的核心数学运算的这些错误:

System.Windows.Forms.Button 不包含 ToInt32 的定义,并且没有可以找到接受类型 System.Windows.Forms.Button 的第一个参数的扩展方法 ToInt32 (您是否缺少using指令或程序集引用?)行:93

方法'ToString'没有重载需要2个参数行:94

System.Windows.Forms.Button不包含'ToInt32'的定义,并且没有扩展方法'ToInt32'接受类型'System.Windows.Forms.Button'的第一个参数可以找到(你是否缺少using指令或者装配参考?)线:103

这是代码:

public void Convert_Click(object sender, EventArgs e)
    {
        string Input;
        bool IsNotBinary;
        string Answer;
        Start:
        Input = UserInput.Text;
        int InputLength = Input.Length;
        if (InputLength > 10)
        {
            UserInput.Text = "Overflow";
            goto Start;
        }
        int Int;
        bool IsANumber = int.TryParse(Input, out Int);
        if (IsANumber == false)
        {
            UserInput.Text = "Invalid Character";
            goto Start;
        }
        IsNotBinary = Input.Contains("3");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("4");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("5");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("6");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("7");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("8");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("9");
    End:

        if (IsNotBinary == true)
        {

            // decimal to binary
            int InputInt = Convert.ToInt32(Input); // converts the string "Input" to the int "InputInt"
            Answer = Convert.ToString(InputInt, 2);
            UserInput.Text = Answer;

        }

        else
        {

            // binary to decimal
            Answer = Convert.ToInt32(Input, 2).ToString();
            UserInput.Text = Answer;

        }
        Console.ReadLine();
        goto Start;
    }

    public void QuitButton_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }        
}

}

1 回答

  • 7

    错误消息非常清楚:

    System.Windows.Forms.Button'不包含'ToInt32'的定义

    我的通灵调试器告诉我你有一个名为 Convert 的类级别按钮变量,所以你没有在静态 Convert 类上调用 ToInt32 方法,因为你的按钮隐藏了它 . 重命名按钮或完全限定名称,即 System.Convert.ToInt32() .

    编辑:

    好吧,我想我毕竟不需要我的通灵调试器 . 你的事件处理程序告诉我我需要知道的一切:

    public void Convert_Click(...)
    

相关问题