Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#

Validating Edit Controls

Rate me:
Please Sign up or sign in to vote.
4.88/5 (119 votes)
22 Feb 200416 min read 601.4K   5.1K   219  
The classes presented in this article provide benefits for the most popular types of data that may be entered.
/**
 * AMS.TextBox Demo
 * 
 * Written by Alvaro Mendez
 * Copyright (c) 2004. All Rights Reserved.
 * 
 * This file contains the main form for the Demo project that 
 * accompanies the AMS.TextBox class library.
 * 
 * Last Updated: Jan. 30, 2004
 */

using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace TextBoxDemoProject 
{
	class MainForm : System.Windows.Forms.Form
	{
		private AMS.TextBox.NumericTextBox txtNumeric;
		private AMS.TextBox.CurrencyTextBox txtCurrency;
		private AMS.TextBox.MaskedTextBox txtMasked;
		private AMS.TextBox.AlphanumericTextBox txtAlphanumeric;
		private AMS.TextBox.DateTextBox txtDate;
		private AMS.TextBox.TimeTextBox txtTime;		
		private System.Windows.Forms.Button button;
		private System.Windows.Forms.GroupBox gbxCharacters;
		private System.Windows.Forms.TextBox txtInvalidCharacters;
		private System.Windows.Forms.CheckBox chkUse24HourFormat;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.GroupBox gbxAlphanumeric;
		private System.Windows.Forms.GroupBox gbxCurrency;
		private System.Windows.Forms.Label label;
		private System.Windows.Forms.CheckBox chkNumericCannotBeNegative;
		private System.Windows.Forms.NumericUpDown txtNumericLeftDigits;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.GroupBox gbxMaskedNumeric;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.GroupBox gbxDate;
		private System.Windows.Forms.CheckBox chkShowSeconds;
		private System.Windows.Forms.NumericUpDown txtNumericRightDigits;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.GroupBox gbxDigitsFromDecimalPoint;
		private System.Windows.Forms.DateTimePicker dtpMaxDate;
		private System.Windows.Forms.TextBox txtNumericAsDouble;
		private System.Windows.Forms.NumericUpDown txtMaxCharacters;
		private System.Windows.Forms.TextBox txtNumericMask;
		private System.Windows.Forms.GroupBox gbxTime;
		private System.Windows.Forms.TextBox txtCurrencyAsDouble;
		private System.Windows.Forms.GroupBox gbxNumeric;
		private System.Windows.Forms.DateTimePicker dtpMinDate;
		
		public MainForm()
		{
			InitializeComponent();

			Trace.Listeners.Add(new TextWriterTraceListener(System.Console.Out));
			Trace.AutoFlush = true;	

			// Initialize the controls' behaviors
			txtNumericLeftDigitsTextChanged(null, null);
			txtNumericRightDigitsTextChanged(null, null);
			chkNumericCannotBeNegativeCheckedChanged(null, null);
			txtNumericMaskTextChanged(null, null);
			this.txtInvalidCharacters.Text = new string(txtAlphanumeric.InvalidChars);
			txtMaxCharactersTextChanged(null, null);
			dtpMinDateTextChanged(null, null);
			dtpMaxDateTextChanged(null, null);			
			this.chkUse24HourFormat.Checked = this.txtTime.Show24HourFormat;	
		}
	
		// This method is used in the forms designer.
		// Change this method on you own risk
		void btnExitClick(object sender, System.EventArgs e)
		{
			Close();
		}
		
		void txtNumericTextChanged(object sender, System.EventArgs e)
		{
			this.txtNumericAsDouble.Text = this.txtNumeric.Double.ToString();
		}
		
		void txtNumericLeftDigitsTextChanged(object sender, System.EventArgs e)		
		{
			this.txtNumeric.MaxWholeDigits = Convert.ToInt32(this.txtNumericLeftDigits.Text);
		}

		void txtNumericRightDigitsTextChanged(object sender, System.EventArgs e)
		{			
			this.txtNumeric.MaxDecimalPlaces = Convert.ToInt32(this.txtNumericRightDigits.Text);			
		}
		
		void chkNumericCannotBeNegativeCheckedChanged(object sender, System.EventArgs e)
		{
			this.txtNumeric.AllowNegative = !this.chkNumericCannotBeNegative.Checked;
		}

		void txtCurrencyTextChanged(object sender, System.EventArgs e)
		{
			this.txtCurrencyAsDouble.Text = this.txtCurrency.Double.ToString();			
		}

		void txtNumericMaskTextChanged(object sender, System.EventArgs e)
		{
			this.txtMasked.Mask = this.txtNumericMask.Text;
			if (this.txtNumericMask.Text.Length == 0)
				this.txtMasked.Text = "";			
		}
		
		void txtInvalidCharactersTextChanged(object sender, System.EventArgs e)
		{
			this.txtAlphanumeric.InvalidChars = this.txtInvalidCharacters.Text.ToCharArray();
			if (this.txtInvalidCharacters.Text.Length == 0)
				this.txtAlphanumeric.Text = "";						
		}
		
		void txtMaxCharactersTextChanged(object sender, System.EventArgs e)
		{
			this.txtAlphanumeric.MaxLength = Convert.ToInt32(this.txtMaxCharacters.Text);
			this.txtAlphanumeric.UpdateText();
		}
		
		void dtpMinDateTextChanged(object sender, System.EventArgs e)
		{
			this.txtDate.RangeMin = this.dtpMinDate.Value;
		}
		
		void dtpMaxDateTextChanged(object sender, System.EventArgs e)
		{
			this.txtDate.RangeMax = this.dtpMaxDate.Value;			
		}		
		
		void chkUse24HourFormatCheckedChanged(object sender, System.EventArgs e)
		{
			this.txtTime.Show24HourFormat = this.chkUse24HourFormat.Checked;	
			this.txtTime.Focus();
		}
		
		void chkShowSecondsCheckedChanged(object sender, System.EventArgs e)
		{
			this.txtTime.ShowSeconds = this.chkShowSeconds.Checked;				
			this.txtTime.Focus();
		}

		void InitializeComponent()
		{
			this.txtNumeric = new AMS.TextBox.NumericTextBox();
			this.txtCurrency = new AMS.TextBox.CurrencyTextBox();
			this.txtMasked = new AMS.TextBox.MaskedTextBox();
			this.txtAlphanumeric = new AMS.TextBox.AlphanumericTextBox();
			this.txtDate = new AMS.TextBox.DateTextBox();
			this.txtTime = new AMS.TextBox.TimeTextBox();
			this.dtpMinDate = new System.Windows.Forms.DateTimePicker();
			this.gbxNumeric = new System.Windows.Forms.GroupBox();
			this.txtCurrencyAsDouble = new System.Windows.Forms.TextBox();
			this.gbxTime = new System.Windows.Forms.GroupBox();
			this.txtNumericMask = new System.Windows.Forms.TextBox();
			this.txtMaxCharacters = new System.Windows.Forms.NumericUpDown();
			this.txtNumericAsDouble = new System.Windows.Forms.TextBox();
			this.dtpMaxDate = new System.Windows.Forms.DateTimePicker();
			this.gbxDigitsFromDecimalPoint = new System.Windows.Forms.GroupBox();
			this.label7 = new System.Windows.Forms.Label();
			this.txtNumericRightDigits = new System.Windows.Forms.NumericUpDown();
			this.chkShowSeconds = new System.Windows.Forms.CheckBox();
			this.gbxDate = new System.Windows.Forms.GroupBox();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.gbxMaskedNumeric = new System.Windows.Forms.GroupBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.txtNumericLeftDigits = new System.Windows.Forms.NumericUpDown();
			this.chkNumericCannotBeNegative = new System.Windows.Forms.CheckBox();
			this.label = new System.Windows.Forms.Label();
			this.gbxCurrency = new System.Windows.Forms.GroupBox();
			this.gbxAlphanumeric = new System.Windows.Forms.GroupBox();
			this.btnExit = new System.Windows.Forms.Button();
			this.chkUse24HourFormat = new System.Windows.Forms.CheckBox();
			this.txtInvalidCharacters = new System.Windows.Forms.TextBox();
			this.gbxCharacters = new System.Windows.Forms.GroupBox();
			this.button = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.txtMaxCharacters)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.txtNumericRightDigits)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.txtNumericLeftDigits)).BeginInit();
			this.SuspendLayout();
			this.gbxCharacters.SuspendLayout();
			this.gbxAlphanumeric.SuspendLayout();
			this.gbxCurrency.SuspendLayout();
			this.txtNumericLeftDigits.SuspendLayout();
			this.gbxMaskedNumeric.SuspendLayout();
			this.gbxDate.SuspendLayout();
			this.txtNumericRightDigits.SuspendLayout();
			this.gbxDigitsFromDecimalPoint.SuspendLayout();
			this.txtMaxCharacters.SuspendLayout();
			this.gbxTime.SuspendLayout();
			this.gbxNumeric.SuspendLayout();
			// 
			// dtpMinDate
			// 
			this.dtpMinDate.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.dtpMinDate.CustomFormat = "";
			this.dtpMinDate.Format = System.Windows.Forms.DateTimePickerFormat.Short;
			this.dtpMinDate.Location = new System.Drawing.Point(8, 72);
			this.dtpMinDate.Name = "dtpMinDate";
			this.dtpMinDate.Size = new System.Drawing.Size(152, 21);
			this.dtpMinDate.TabIndex = 2;
			this.dtpMinDate.Value = new System.DateTime(1980, 1, 1, 0, 0, 0, 0);
			this.dtpMinDate.TextChanged += new System.EventHandler(this.dtpMinDateTextChanged);
			// 
			// gbxNumeric
			// 
			this.gbxNumeric.Font = new System.Drawing.Font("MS Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
			this.gbxNumeric.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.txtNumeric,
						this.txtNumericAsDouble,
						this.label3,
						this.chkNumericCannotBeNegative,
						this.gbxDigitsFromDecimalPoint});
			this.gbxNumeric.Location = new System.Drawing.Point(8, 12);
			this.gbxNumeric.Name = "gbxNumeric";
			this.gbxNumeric.Size = new System.Drawing.Size(168, 228);
			this.gbxNumeric.TabIndex = 0;
			this.gbxNumeric.TabStop = false;
			this.gbxNumeric.Text = "Numeric";
			// 
			// txtCurrencyAsDouble
			// 
			this.txtCurrencyAsDouble.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtCurrencyAsDouble.Location = new System.Drawing.Point(8, 72);
			this.txtCurrencyAsDouble.Name = "txtCurrencyAsDouble";
			this.txtCurrencyAsDouble.ReadOnly = true;
			this.txtCurrencyAsDouble.Size = new System.Drawing.Size(152, 21);
			this.txtCurrencyAsDouble.TabIndex = 8;
			this.txtCurrencyAsDouble.Text = "";
			// 
			// gbxTime
			// 
			this.gbxTime.Font = new System.Drawing.Font("MS Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
			this.gbxTime.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.chkShowSeconds,
						this.chkUse24HourFormat,
						this.txtTime});
			this.gbxTime.Location = new System.Drawing.Point(188, 336);
			this.gbxTime.Name = "gbxTime";
			this.gbxTime.Size = new System.Drawing.Size(168, 96);
			this.gbxTime.TabIndex = 6;
			this.gbxTime.TabStop = false;
			this.gbxTime.Text = "Time";
			// 
			// txtMasked
			// 
			this.txtMasked.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtMasked.Location = new System.Drawing.Point(8, 23);
			this.txtMasked.Name = "txtMasked";
			this.txtMasked.Size = new System.Drawing.Size(152, 21);
			this.txtMasked.TabIndex = 9;
			this.txtMasked.Text = "";
			// 
			// txtNumericMask
			// 
			this.txtNumericMask.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtNumericMask.Location = new System.Drawing.Point(8, 72);
			this.txtNumericMask.Name = "txtNumericMask";
			this.txtNumericMask.Size = new System.Drawing.Size(152, 21);
			this.txtNumericMask.TabIndex = 10;
			this.txtNumericMask.TextChanged += new System.EventHandler(this.txtNumericMaskTextChanged);
			this.txtNumericMask.Text = "(###) ###-#### x####";
			// 
			// txtMaxCharacters
			// 
			this.txtMaxCharacters.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtMaxCharacters.Location = new System.Drawing.Point(54, 56);
			this.txtMaxCharacters.Maximum = new System.Decimal(new int[] {
						500,
						0,
						0,
						0});
			this.txtMaxCharacters.Minimum = new System.Decimal(new int[] {
						1,
						0,
						0,
						0});
			this.txtMaxCharacters.Name = "txtMaxCharacters";
			this.txtMaxCharacters.Size = new System.Drawing.Size(88, 21);
			this.txtMaxCharacters.TabIndex = 3;
			this.txtMaxCharacters.Value = new System.Decimal(new int[] {
						20,
						0,
						0,
						0});
			this.txtMaxCharacters.TextChanged += new System.EventHandler(this.txtMaxCharactersTextChanged);
			// 
			// txtTime
			// 
			this.txtTime.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtTime.Location = new System.Drawing.Point(8, 20);
			this.txtTime.Name = "txtTime";
			this.txtTime.Size = new System.Drawing.Size(152, 21);
			this.txtTime.TabIndex = 0;
			this.txtTime.Text = "";
			// 
			// txtDate
			// 
			this.txtDate.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtDate.Location = new System.Drawing.Point(8, 21);
			this.txtDate.Name = "txtDate";
			this.txtDate.Size = new System.Drawing.Size(152, 21);
			this.txtDate.TabIndex = 0;
			this.txtDate.Text = "";
			// 
			// txtNumericAsDouble
			// 
			this.txtNumericAsDouble.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtNumericAsDouble.Location = new System.Drawing.Point(8, 196);
			this.txtNumericAsDouble.Name = "txtNumericAsDouble";
			this.txtNumericAsDouble.ReadOnly = true;
			this.txtNumericAsDouble.Size = new System.Drawing.Size(152, 21);
			this.txtNumericAsDouble.TabIndex = 6;
			this.txtNumericAsDouble.Text = "";
			// 
			// dtpMaxDate
			// 
			this.dtpMaxDate.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.dtpMaxDate.Format = System.Windows.Forms.DateTimePickerFormat.Short;
			this.dtpMaxDate.Location = new System.Drawing.Point(8, 120);
			this.dtpMaxDate.Name = "dtpMaxDate";
			this.dtpMaxDate.Size = new System.Drawing.Size(152, 21);
			this.dtpMaxDate.TabIndex = 4;
			this.dtpMaxDate.Value = new System.DateTime(2010, 12, 31, 0, 0, 0, 0);
			this.dtpMaxDate.TextChanged += new System.EventHandler(this.dtpMaxDateTextChanged);
			// 
			// gbxDigitsFromDecimalPoint
			// 
			this.gbxDigitsFromDecimalPoint.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.txtNumericRightDigits,
						this.txtNumericLeftDigits,
						this.label2,
						this.label});
			this.gbxDigitsFromDecimalPoint.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.gbxDigitsFromDecimalPoint.Location = new System.Drawing.Point(10, 56);
			this.gbxDigitsFromDecimalPoint.Name = "gbxDigitsFromDecimalPoint";
			this.gbxDigitsFromDecimalPoint.Size = new System.Drawing.Size(150, 88);
			this.gbxDigitsFromDecimalPoint.TabIndex = 2;
			this.gbxDigitsFromDecimalPoint.TabStop = false;
			this.gbxDigitsFromDecimalPoint.Text = " Digits from Decimal Point";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(8, 58);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(40, 16);
			this.label7.TabIndex = 2;
			this.label7.Text = "Max:";
			// 
			// txtNumericRightDigits
			// 
			this.txtNumericRightDigits.Location = new System.Drawing.Point(56, 56);
			this.txtNumericRightDigits.Maximum = new System.Decimal(new int[] {
						9,
						0,
						0,
						0});
			this.txtNumericRightDigits.Name = "txtNumericRightDigits";
			this.txtNumericRightDigits.Size = new System.Drawing.Size(80, 21);
			this.txtNumericRightDigits.TabIndex = 4;
			this.txtNumericRightDigits.Value = new System.Decimal(new int[] {
						9,
						0,
						0,
						0});
			this.txtNumericRightDigits.TextChanged += new System.EventHandler(this.txtNumericRightDigitsTextChanged);
			// 
			// chkShowSeconds
			// 
			this.chkShowSeconds.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.chkShowSeconds.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.chkShowSeconds.Location = new System.Drawing.Point(8, 73);
			this.chkShowSeconds.Name = "chkShowSeconds";
			this.chkShowSeconds.Size = new System.Drawing.Size(152, 16);
			this.chkShowSeconds.TabIndex = 2;
			this.chkShowSeconds.Text = "Show seconds:";
			this.chkShowSeconds.CheckedChanged += new System.EventHandler(this.chkShowSecondsCheckedChanged);
			// 
			// gbxDate
			// 
			this.gbxDate.Font = new System.Drawing.Font("MS Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
			this.gbxDate.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.dtpMaxDate,
						this.label9,
						this.dtpMinDate,
						this.label8,
						this.txtDate});
			this.gbxDate.Location = new System.Drawing.Point(188, 176);
			this.gbxDate.Name = "gbxDate";
			this.gbxDate.Size = new System.Drawing.Size(168, 152);
			this.gbxDate.TabIndex = 5;
			this.gbxDate.TabStop = false;
			this.gbxDate.Text = "Date";
			// 
			// label8
			// 
			this.label8.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.label8.Location = new System.Drawing.Point(8, 56);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(136, 16);
			this.label8.TabIndex = 1;
			this.label8.Text = "Minimum:";
			// 
			// label9
			// 
			this.label9.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.label9.Location = new System.Drawing.Point(8, 104);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(112, 16);
			this.label9.TabIndex = 3;
			this.label9.Text = "Maximum:";
			// 
			// txtNumeric
			// 
			this.txtNumeric.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtNumeric.Location = new System.Drawing.Point(8, 20);
			this.txtNumeric.Name = "txtNumeric";
			this.txtNumeric.Size = new System.Drawing.Size(152, 21);
			this.txtNumeric.TabIndex = 1;
			this.txtNumeric.Text = "";
			this.txtNumeric.TextChanged += new System.EventHandler(this.txtNumericTextChanged);
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.label4.Location = new System.Drawing.Point(8, 56);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(128, 16);
			this.label4.TabIndex = 5;
			this.label4.Text = "Value as a Double:";
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.label5.Location = new System.Drawing.Point(8, 56);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(128, 16);
			this.label5.TabIndex = 7;
			this.label5.Text = "Mask (# = digit):";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(8, 27);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(48, 16);
			this.label6.TabIndex = 0;
			this.label6.Text = "Invalid:";
			// 
			// gbxMaskedNumeric
			// 
			this.gbxMaskedNumeric.Font = new System.Drawing.Font("MS Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
			this.gbxMaskedNumeric.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.txtNumericMask,
						this.label5,
						this.txtMasked});
			this.gbxMaskedNumeric.Location = new System.Drawing.Point(8, 360);
			this.gbxMaskedNumeric.Name = "gbxMaskedNumeric";
			this.gbxMaskedNumeric.Size = new System.Drawing.Size(168, 104);
			this.gbxMaskedNumeric.TabIndex = 3;
			this.gbxMaskedNumeric.TabStop = false;
			this.gbxMaskedNumeric.Text = "Masked Numeric";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 58);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "Right:";
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.label3.Location = new System.Drawing.Point(8, 178);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(128, 16);
			this.label3.TabIndex = 3;
			this.label3.Text = "Value as a Double:";
			// 
			// txtNumericLeftDigits
			// 
			this.txtNumericLeftDigits.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtNumericLeftDigits.Location = new System.Drawing.Point(56, 24);
			this.txtNumericLeftDigits.Maximum = new System.Decimal(new int[] {
						9,
						0,
						0,
						0});
			this.txtNumericLeftDigits.Minimum = new System.Decimal(new int[] {
						1,
						0,
						0,
						0});
			this.txtNumericLeftDigits.Name = "txtNumericLeftDigits";
			this.txtNumericLeftDigits.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtNumericLeftDigits.Size = new System.Drawing.Size(80, 21);
			this.txtNumericLeftDigits.TabIndex = 3;
			this.txtNumericLeftDigits.Value = new System.Decimal(new int[] {
						8,
						0,
						0,
						0});
			this.txtNumericLeftDigits.TextChanged += new System.EventHandler(this.txtNumericLeftDigitsTextChanged);
			// 
			// txtAlphanumeric
			// 
			this.txtAlphanumeric.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtAlphanumeric.Location = new System.Drawing.Point(8, 20);
			this.txtAlphanumeric.Name = "txtAlphanumeric";
			this.txtAlphanumeric.Size = new System.Drawing.Size(152, 21);
			this.txtAlphanumeric.TabIndex = 0;
			this.txtAlphanumeric.Text = "";
			// 
			// chkNumericCannotBeNegative
			// 
			this.chkNumericCannotBeNegative.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.chkNumericCannotBeNegative.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.chkNumericCannotBeNegative.Location = new System.Drawing.Point(8, 156);
			this.chkNumericCannotBeNegative.Name = "chkNumericCannotBeNegative";
			this.chkNumericCannotBeNegative.Size = new System.Drawing.Size(152, 16);
			this.chkNumericCannotBeNegative.TabIndex = 5;
			this.chkNumericCannotBeNegative.Text = "Cannot be negative:";
			this.chkNumericCannotBeNegative.CheckedChanged += new System.EventHandler(this.chkNumericCannotBeNegativeCheckedChanged);
			// 
			// label
			// 
			this.label.Location = new System.Drawing.Point(8, 27);
			this.label.Name = "label";
			this.label.Size = new System.Drawing.Size(32, 16);
			this.label.TabIndex = 0;
			this.label.Text = "Left:";
			// 
			// gbxCurrency
			// 
			this.gbxCurrency.Font = new System.Drawing.Font("MS Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
			this.gbxCurrency.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.txtCurrency,
						this.txtCurrencyAsDouble,
						this.label4});
			this.gbxCurrency.Location = new System.Drawing.Point(8, 248);
			this.gbxCurrency.Name = "gbxCurrency";
			this.gbxCurrency.Size = new System.Drawing.Size(168, 104);
			this.gbxCurrency.TabIndex = 1;
			this.gbxCurrency.TabStop = false;
			this.gbxCurrency.Text = "Currency";
			// 
			// gbxAlphanumeric
			// 
			this.gbxAlphanumeric.Font = new System.Drawing.Font("MS Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
			this.gbxAlphanumeric.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.gbxCharacters,
						this.txtAlphanumeric});
			this.gbxAlphanumeric.Location = new System.Drawing.Point(188, 12);
			this.gbxAlphanumeric.Name = "gbxAlphanumeric";
			this.gbxAlphanumeric.Size = new System.Drawing.Size(168, 156);
			this.gbxAlphanumeric.TabIndex = 4;
			this.gbxAlphanumeric.TabStop = false;
			this.gbxAlphanumeric.Text = "Alphanumeric";
			// 
			// btnExit
			// 
			this.btnExit.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.btnExit.Location = new System.Drawing.Point(276, 443);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(80, 24);
			this.btnExit.TabIndex = 7;
			this.btnExit.Text = "Exit";
			this.btnExit.Click += new System.EventHandler(this.btnExitClick);
			// 
			// chkUse24HourFormat
			// 
			this.chkUse24HourFormat.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.chkUse24HourFormat.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.chkUse24HourFormat.Location = new System.Drawing.Point(8, 52);
			this.chkUse24HourFormat.Name = "chkUse24HourFormat";
			this.chkUse24HourFormat.Size = new System.Drawing.Size(152, 16);
			this.chkUse24HourFormat.TabIndex = 1;
			this.chkUse24HourFormat.Text = "Use 24-hour format:";
			this.chkUse24HourFormat.CheckedChanged += new System.EventHandler(this.chkUse24HourFormatCheckedChanged);
			// 
			// txtCurrency
			// 
			this.txtCurrency.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.txtCurrency.Location = new System.Drawing.Point(8, 22);
			this.txtCurrency.Name = "txtCurrency";
			this.txtCurrency.Size = new System.Drawing.Size(152, 21);
			this.txtCurrency.TabIndex = 7;
			this.txtCurrency.Text = "";
			this.txtCurrency.TextChanged += new System.EventHandler(this.txtCurrencyTextChanged);
			// 
			// txtInvalidCharacters
			// 
			this.txtInvalidCharacters.Location = new System.Drawing.Point(53, 24);
			this.txtInvalidCharacters.Name = "txtInvalidCharacters";
			this.txtInvalidCharacters.Size = new System.Drawing.Size(88, 21);
			this.txtInvalidCharacters.TabIndex = 1;
			this.txtInvalidCharacters.Text = "";
			this.txtInvalidCharacters.TextChanged += new System.EventHandler(this.txtInvalidCharactersTextChanged);
			// 
			// gbxCharacters
			// 
			this.gbxCharacters.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.txtMaxCharacters,
						this.label7,
						this.txtInvalidCharacters,
						this.label6});
			this.gbxCharacters.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.gbxCharacters.Location = new System.Drawing.Point(8, 56);
			this.gbxCharacters.Name = "gbxCharacters";
			this.gbxCharacters.Size = new System.Drawing.Size(152, 88);
			this.gbxCharacters.TabIndex = 1;
			this.gbxCharacters.TabStop = false;
			this.gbxCharacters.Text = "Characters";
			// 
			// button
			// 
			this.txtMasked.Font = new System.Drawing.Font("MS Sans Serif", 8.25F);
			this.button.Location = new System.Drawing.Point(280, 264);
			this.button.Name = "button";
			this.button.Size = new System.Drawing.Size(80, 24);
			this.button.TabIndex = 1;
			this.button.Text = "Exit";
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(363, 475);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
						this.gbxTime,
						this.gbxDate,
						this.gbxAlphanumeric,
						this.gbxMaskedNumeric,
						this.gbxCurrency,
						this.btnExit,
						this.gbxNumeric});
			this.Font = new System.Drawing.Font("MS Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Name = "MainForm";
			this.Text = "Validating Edit Demo";
			((System.ComponentModel.ISupportInitialize)(this.txtMaxCharacters)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.txtNumericRightDigits)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.txtNumericLeftDigits)).EndInit();
			this.gbxNumeric.ResumeLayout(false);
			this.gbxTime.ResumeLayout(false);
			this.txtMaxCharacters.ResumeLayout(false);
			this.gbxDigitsFromDecimalPoint.ResumeLayout(false);
			this.txtNumericRightDigits.ResumeLayout(false);
			this.gbxDate.ResumeLayout(false);
			this.gbxMaskedNumeric.ResumeLayout(false);
			this.txtNumericLeftDigits.ResumeLayout(false);
			this.gbxCurrency.ResumeLayout(false);
			this.gbxAlphanumeric.ResumeLayout(false);
			this.gbxCharacters.ResumeLayout(false);
			this.ResumeLayout(false);
		}
			
		[STAThread]
		public static void Main(string[] args)
		{
			Application.Run(new MainForm());
		}
	}			
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I've done extensive work with C++, MFC, COM, and ATL on the Windows side. On the Web side, I've worked with VB, ASP, JavaScript, and COM+. I've also been involved with server-side Java, which includes JSP, Servlets, and EJB, and more recently with ASP.NET/C#.

Comments and Discussions