using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace Common { /// <summary> /// TextBox控件操作類 /// </summary> public class CtlTextBoxOperate { private TextBox m_textBox = null; /// <summary> /// TextBox控件 /// </summary> public TextBox refTextBoxControl { set { m_textBox = value; } get { return m_textBox; } } /// <summary> /// 構造函數 /// </summary> public CtlTextBoxOperate() { } private static volatile CtlTextBoxOperate m_tbOpera = null; /// <summary> ///獲取操作TextBox控件的單一實例 /// </summary> public static CtlTextBoxOperate GetInstance() { if(null == m_tbOpera) { m_tbOpera = new CtlTextBoxOperate(); } return m_tbOpera; } /// <summary> /// 只能輸入整數! /// </summary> /// <param name="e"></param> public void InputIntDigit(KeyPressEventArgs e) { if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8)) //48代表0,57代表9,8代表空格,46代表小數點 { e.Handled = true; } } /// <summary> /// 只能輸入數! /// </summary> /// <param name="e"></param> public void InputDigit(KeyPressEventArgs e) { if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && e.KeyChar != 46) //48代表0,57代表9,8代表空格,46代表小數點 { e.Handled = true; } } } }