IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

Composante ErrorProvider c# gui


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Avatar de mihaispr
    Inscrit en
    Décembre 2008
    Messages
    1 025
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 025
    Par défaut Composante ErrorProvider c# gui
    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?

  2. #2
    Membre Expert
    Avatar de laedit
    Homme Profil pro
    Consultant études et développement
    Inscrit en
    Décembre 2006
    Messages
    1 344
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Consultant études et développement
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 344
    Par défaut
    Tu as deux méthodes Main() qui définissent un point d'entrée de l'application.
    Or tu ne dois en avoir qu'un seul. Regarde d'où proviennent ces méthodes et ce qu'elles font, l'une d'entre elle doit créer ton formulaire principale.
    Il faudra que tu modifie l'autre en la renommant ou en la supprimant.
    Blog - Articles - Framework

    MSDN vous aide, si si, alors n'hésitez pas à y faire un tour avant de poser une question.
    Ah, et n'oubliez pas, Google peut répondre à la majorité de vos questions.

Discussions similaires

  1. Composante HelpProvider gui C#
    Par mihaispr dans le forum Windows Forms
    Réponses: 1
    Dernier message: 14/09/2009, 08h20
  2. Composante pour stoquer un modele simulink dans un gui
    Par mihaispr dans le forum Interfaces Graphiques
    Réponses: 2
    Dernier message: 04/05/2009, 18h43
  3. [editeur GUI][info]
    Par lunatix dans le forum Eclipse Java
    Réponses: 5
    Dernier message: 26/01/2004, 15h59
  4. [GUI] Ou trouver les standard ?
    Par Braim dans le forum Windows
    Réponses: 5
    Dernier message: 01/10/2003, 08h13
  5. TObject->Color et composantes RGB
    Par Flo. dans le forum C++Builder
    Réponses: 10
    Dernier message: 14/06/2002, 17h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo