C# 应为类、委托、枚举、接口或结构?发生了什么?

C# 应为类、委托、枚举、接口或结构?发生了什么?,c#,enums,C#,Enums,我已经研究了方法和字段并阅读了它们。我想我把一些代码放错地方了?我需要添加或删除某些内容吗?我知道这是个愚蠢的错误 问题:您正在类外编写TextBox1\u TextChanged事件处理程序 解决方案:您需要将TextBox1\u TextChanged事件处理程序移动到类Form1中 试试这个: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usi

我已经研究了方法和字段并阅读了它们。我想我把一些代码放错地方了?我需要添加或删除某些内容吗?我知道这是个愚蠢的错误

问题:您正在类外编写TextBox1\u TextChanged事件处理程序

解决方案:您需要将TextBox1\u TextChanged事件处理程序移动到类Form1中

试试这个:

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;
using Microsoft.VisualBasic;
using System.Collections;
using System.Diagnostics;

namespace NumbertoWordHamza
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

    }
}
private void TextBox1_TextChanged(System.Object sender, System.EventArgs e)
{
    if (!Information.IsNumeric(TextBox1.Text)) {
        TextBox2.Text = "";
        return;
    }

    TextBox2.Text = GetTextForNumber(TextBox1.Text);

}
您的TextBox1_TextChanged方法似乎不是类型的一部分。。。所有方法都必须是类型的一部分。
namespace NumbertoWordHamza
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void TextBox1_TextChanged(System.Object sender, System.EventArgs e)
        {
            if (!Information.IsNumeric(TextBox1.Text))
            {
                TextBox2.Text = "";
                return;
            }
            TextBox2.Text = GetTextForNumber(TextBox1.Text);
        }   
    }
}