Sur ma forme j'ai ca:



http://www.java2s.com/Tutorial/CShar...Textlength.htm



Le code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
 
public class ErrorForm : System.Windows.Forms.Form
{
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Button btnValidate;
    private System.Windows.Forms.ErrorProvider errorProvider1;
    private System.Windows.Forms.TextBox txtInput;
 
    public ErrorForm() - erreur ici!
    {
        InitializeComponent();
    }
 
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            if (components != null)
            {
                components.Dispose();
            }
        }
        base.Dispose(disposing);
    }
 
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.errorProvider1 = new System.Windows.Forms.ErrorProvider(this.components);
        this.label1 = new System.Windows.Forms.Label();
        this.txtInput = new System.Windows.Forms.TextBox();
        this.btnValidate = new System.Windows.Forms.Button();
        ((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).BeginInit();
        this.SuspendLayout();
        // 
        // errorProvider1
        // 
        this.errorProvider1.BlinkRate = 500;
        this.errorProvider1.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.AlwaysBlink;
        this.errorProvider1.ContainerControl = this;
        // 
        // label1
        // 
        this.label1.Font = new System.Drawing.Font("Arial Black", 12F);
        this.label1.Location = new System.Drawing.Point(8, 8);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(376, 56);
        this.label1.TabIndex = 2;
        this.label1.Text = "The following text box only allows 5 characters.  Try to enter more...";
        // 
        // txtInput
        // 
        this.txtInput.Location = new System.Drawing.Point(144, 80);
        this.txtInput.Name = "txtInput";
        this.txtInput.Size = new System.Drawing.Size(120, 20);
        this.txtInput.TabIndex = 0;
        this.txtInput.Validating += new System.ComponentModel.CancelEventHandler(this.txtInput_Validating);
        // 
        // btnValidate
        // 
        this.btnValidate.Location = new System.Drawing.Point(16, 72);
        this.btnValidate.Name = "btnValidate";
        this.btnValidate.Size = new System.Drawing.Size(112, 32);
        this.btnValidate.TabIndex = 1;
        this.btnValidate.Text = "OK";
        // 
        // ErrorForm
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(400, 125);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.btnValidate);
        this.Controls.Add(this.txtInput);
        this.Name = "ErrorForm";
        this.Text = "Error Trapper";
        ((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).EndInit();
        this.ResumeLayout(false);
        this.PerformLayout();
 
    }
 
    [STAThread]
    static void Main() -erreur ici!!!
    {
        Application.Run(new Form1());
    }
 
    private void txtInput_Validating(object sender, System.ComponentModel.CancelEventArgs e)
    {
        // Check if the text length is greater than 5.
        if (txtInput.Text.Length > 5)
        {
            errorProvider1.SetError(txtInput, "Can't be greater than 5!");
        }
        else
            errorProvider1.SetError(txtInput, "");
    }
 
    private IContainer components;
}
J'ai les 2 erreurs d'ici:



Comment je dois modifier le code pour que les 2 erreurs disparaissent?