using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace StCtlLib
{
	/// <summary>
	/// </summary>
	public class StTextBox : TextBox
	{
		/// <summary>
		/// </summary>
		private System.ComponentModel.Container components = null;

		public StTextBox()
		{
			InitializeComponent();

            TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
		}

		/// <summary>
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region 
		/// <summary>
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// StTextBox
			// 
			this.Name = "StTextBox";

		}
		#endregion

		public event TextEnteredEventHandler TextEntered;
		protected virtual void OnTextEntered(TextEnteredEventArgs e)
		{
			if(TextEntered != null)
			{
				TextEntered(this, e);
			}
		}

	
		protected override void OnKeyDown(KeyEventArgs e)
		{
			if(e.KeyCode == Keys.Enter)
			{
				TextEnteredEventArgs tev = new TextEnteredEventArgs(Text);
				OnTextEntered(tev);
				e.Handled = true;
				return;
			}
			
			base.OnKeyDown (e);
		}
	}
	public class TextEnteredEventArgs : EventArgs
	{
		private string enteredText;
		private bool handled;
		internal TextEnteredEventArgs(string s)
		{
			enteredText = s;
			handled = false;
		}
		public string Text
		{
			get
			{
				return(enteredText);
			}
		}
		public bool Handled
		{
			get
			{
				return(handled);
			}
			set
			{
				handled = value;
			}
		}
	}
	public delegate void TextEnteredEventHandler(object sender, TextEnteredEventArgs e);
}
