0

我刚开始学习 C# 并开始使用 Windows Forms 项目。当我尝试验证文本字段时,我收到此错误:

错误 1“Downloader.SDownloader”不包含“errorProvider1”的定义,并且找不到接受“Downloader.SDownloader”类型的第一个参数的扩展方法“errorProvider1”(您是否缺少 using 指令或程序集引用?) C:\Users\Bad_Wolf\documents\visual studio 2010\Projects\Register\Register\Form1.cs 77 22 注册

有我的源代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Downloader {
    public partial class SDownloader : Form {
        public SDownloader() {
            InitializeComponent();
        }
        private void fname_MouseClick(object sender, MouseEventArgs e) {
           fname.Text = "";
        }
        private void fname_TextChanged(object sender, EventArgs e) {

        }
        private void lname_MouseClick(object sender, MouseEventArgs e) {
            lname.Text = "";
        }
        private void lname_TextChanged(object sender, EventArgs e) {

        }
        private void username_MouseClick(object sender, MouseEventArgs e) {
            username.Text = "";
        }
        private void email_MouseClick(object sender, MouseEventArgs e) {
            email.Text = "";
        }
        private void password_MouseClick(object sender, MouseEventArgs e) {
            password.Text = "";
        }
        private void password2_MouseClick(object sender, MouseEventArgs e) {
            password2.Text = "";
        }
        private void password2_TextChanged(object sender, EventArgs e) {

        }
        private void register_Click(object sender, EventArgs e) {

        }
        private void fname_Validating(object sender, CancelEventArgs e) {
            string errorMsg;
            if (fname.Text.Trim().Length < 4) {
                e.Cancel = true;
                fname.Select(0, fname.Text.Length);
                this.errorProvider1.SetError(fname, errorMsg);
            }
        }
        private void fname_Validated(object sender, EventArgs e) {

        }
    }
}
4

1 回答 1

0

您收到此错误的原因是您没有在设计视图中将ErrorProvider添加到表单中。添加 ErrorProvider 并为其命名errorProvider1

在此处输入图像描述

于 2012-06-28T10:30:00.473 回答