public class cgsTextBox : System.Windows.Forms.TextBox { public override Font Font { get {return base.Font; } set {base.Font = value; } } private DataTable m_DtSource; public DataTable DtSource { get {return m_DtSource ;} set {m_DtSource = value; } } private DataColumn m_DcSource; public DataColumn DcSource { get {return m_DcSource ;} set {m_DcSource = value; } } private bool m_lDecimal; public bool lDecimal { get {return m_lDecimal ;} set {m_lDecimal = value; } } public cgdTextBox() { base.Font = new Font("Verdana",8); this.Enter += new EventHandler(OnEnter); this.Leave += new EventHandler(OnLeave); this.KeyDown += new KeyEventHandler(OnKeyDown); } public void DecimalToCurrencyString(object sender, ConvertEventArgs cevent) { if(cevent.DesiredType != typeof(string)) return; cevent.Value = ((decimal) cevent.Value).ToString("F2"); } public void CurrencyStringToDecimal(object sender, ConvertEventArgs cevent) { if(cevent.DesiredType != typeof(decimal)) return; cevent.Value = Decimal.Parse(cevent.Value.ToString(),NumberStyles.Currency, null); } public void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter) SendKeys.Send("{TAB}"); } public void OnEnter(object sender,EventArgs e ) { this.SelectAll(); this.BackColor = Color.Yellow; } public void OnLeave(object sender,EventArgs e ) { this.BackColor = Color.White; } public void BindControl() { if(this.m_DcSource != null) { this.DataBindings.Clear(); System.Windows.Forms.Binding newBinding ; newBinding = new System.Windows.Forms.Binding( "Text",this.m_DtSource,this.m_DcSource.ColumnName.ToString()); if(this.lDecimal==true) { this.TextAlign = HorizontalAlignment.Right; newBinding.Format += new ConvertEventHandler(this.DecimalToCurrencyString); newBinding.Parse += new ConvertEventHandler(this.CurrencyStringToDecimal); } this.DataBindings.Add(newBinding); } } }