C#:TextBox控件操作類


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;
            }
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM