using System;
using System.Drawing ;

namespace EmailTextBoxControl
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>

	// Derive a class from the system-provided TextBox

	public class Class1 : System.Windows.Forms.TextBox 
	{

		private Color m_GoodColor = Color.LightGreen ;
		private Color m_BadColor = Color.Pink ;

		public Color GoodColor
		{
			get { return m_GoodColor ; }
			set { m_GoodColor = value ; } 
		}

		public Color BadColor
		{
			get { return m_BadColor ; } 
			set { m_BadColor = value ; } 
		}

		// Override the OnTextChanged method. This gets called
		// whenever the text inside the text box changes for
		// any reason

		protected override void OnTextChanged(EventArgs e)
		{
			// Simplified check to see if the text string is a valid
			// a valid e-mail address. Set the control's 
			// background color to green if so, pink if not

			if (this.Text.IndexOf ("@") != -1 &&
				this.Text.IndexOf (".") != -1 )
			{
				this.BackColor = m_GoodColor ;
			}
			else
			{
				this.BackColor = m_BadColor ;
			}

			// Forward the call to the base class so we don't
			// break its functionality

			base.OnTextChanged (e);
		}



	}
}
