首页 > 代码库 > C#:TextBox控件操作类

C#:TextBox控件操作类

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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;
            }
        }
    }
}