期望的类、委托、枚举、接口或结构?你们# 39;年代错误的

本文关键字:错误 你们 结构 委托 枚举 接口 期望 | 更新日期: 2023-09-27 17:50:35

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);
}

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

期望的类、委托、枚举、接口或结构?你们# 39;年代错误的

问题:您正在编写TextBox1_TextChanged事件处理程序以外的类。

解决方案:您需要将TextBox1_TextChanged事件处理程序移动到Form1类中。

试试这个:

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);
        }   
    }
}