ErrorProvider: Text length : ErrorProvider « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » ErrorProvider 
23.32.2.ErrorProvider: Text length
ErrorProvider: Text length
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.ComponentModel.Container components = null;
  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()
  {
    InitializeComponent();
  }

  protected override void Disposebool disposing )
  {
    ifdisposing )
    {
      if (components != null
      {
        components.Dispose();
      }
    }
    base.Disposedisposing );
  }

  private void InitializeComponent()
  {
    this.errorProvider1 = new System.Windows.Forms.ErrorProvider();
    this.label1 = new System.Windows.Forms.Label();
    this.txtInput = new System.Windows.Forms.TextBox();
    this.btnValidate = new System.Windows.Forms.Button();
    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(88);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(37656);
    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(14480);
    this.txtInput.Name = "txtInput";
    this.txtInput.Size = new System.Drawing.Size(12020);
    this.txtInput.TabIndex = 0;
    this.txtInput.Text = "";
    this.txtInput.Validating += new System.ComponentModel.CancelEventHandler(this.txtInput_Validating);
    // 
    // btnValidate
    // 
    this.btnValidate.Location = new System.Drawing.Point(1672);
    this.btnValidate.Name = "btnValidate";
    this.btnValidate.Size = new System.Drawing.Size(11232);
    this.btnValidate.TabIndex = 1;
    this.btnValidate.Text = "OK";
    // 
    // ErrorForm
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(513);
    this.ClientSize = new System.Drawing.Size(400125);
    this.Controls.Add(this.label1);
    this.Controls.Add(this.btnValidate);
    this.Controls.Add(this.txtInput);
    this.Name = "ErrorForm";
    this.Text = "Error Trapper";
    this.ResumeLayout(false);

  }

  [STAThread]
  static void Main() 
  {
    Application.Run(new ErrorForm());
  }

  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.SetErrortxtInput, "Can't be greater than 5!");
    
    else
      errorProvider1.SetError(txtInput, "");
  }
}
23.32.ErrorProvider
23.32.1.ErrorProvider: number must be in a range
23.32.2.ErrorProvider: Text lengthErrorProvider: Text length
23.32.3.Get ErrorMessage from ErrorProviderGet ErrorMessage from ErrorProvider
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.