`

winform 特殊字符判断控件下载

 
阅读更多

以前我听说过一个软件科技公司,写了一个控件,只要在那个软件里面,输入了特殊字符,比如“!,&,^,%,$”,在进行数据交互的时候,就会跳出一个"非法字符操作",而在前不久,我进入了一个科技公司,这家公司也是做winform的,专做大his,健康档案系统的。而在这里面,我就想了一年前朋友们提过非法字符的提示。

      我用了一天多的时间,写了一个winform的特殊字符判断的控件,里面判断了winform的十几种常见文本内容。

     该控件,分两种,一种是只穿控件名,还有种传整个form窗体。 

     而方法里面,是用的多态,才参数,vadite(string[],From),或者vadite(From)

     判断的控件有:

 /// <summary>
        /// 单选框
        /// </summary>
        public static bool validateRadioButton(string[] arr,System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// 复选框
        /// </summary>
        public static bool validateComboBox(string[] arr, System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// 检查文本框
        /// </summary>
        public static bool validateTextBox(string[] arr, System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// 检查下拉框
        /// </summary>
        public static bool validateListBox(string[] arr, System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// 按钮
        /// </summary>
        public static bool validateButton(string[] arr, System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// lable
        /// </summary>
        public static bool validateLabel(string[] arr, System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// linkLable
        /// </summary>
        public static bool validateLinkLabel(string[] arr, System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// CheckedListBox
        /// </summary>
        public static bool validateCheckedListBox(string[] arr, System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// RichTextBox
        /// </summary>
        public static bool validateRichTextBox(string[] arr, System.Windows.Forms.Form frm)
        {
        }
        /// <summary>
        /// 所有控件
        /// </summary>
        public static bool validateRichAllControls(string[] arr, System.Windows.Forms.Form frm)
        {     
        }
        //查询控件下面的子控件数据
        public static bool validateRichAllControlsByControls(string[] arr, System.Windows.Forms.Control control)
        {
        }

 

还有就是传这个窗体,同时,传入的窗体里面有以下控件容器,也会递归去查找他下面的所有子控件的text.进行判断

 if (frm.Controls[i] is Panel)
                {
                    return validateRichAllControlsByControls(arr,frm.Controls[i]);
                }
                if (frm.Controls[i] is GroupBox)
                {
                    return validateRichAllControlsByControls(arr,frm.Controls[i]);
                }
                if (frm.Controls[i] is TabControl)
                {
                    return validateRichAllControlsByControls(arr,frm.Controls[i]);
                }
                if (frm.Controls[i] is SplitContainer)
                {
                    return validateRichAllControlsByControls(arr,frm.Controls[i]);
                }
                if (frm.Controls[i] is FlowLayoutPanel)
                {
                    return validateRichAllControlsByControls(arr,frm.Controls[i]);
                }
                if (frm.Controls[i] is TableLayoutPanel)
                {
                    return validateRichAllControlsByControls(arr,frm.Controls[i]);
                }

而上面的arr,就是一个string类型的特殊字符数组。这个数组,自己可以定义。

这里有两个调用这个空间的例子

 
           string[] arr = new string[] { "'", "?", "#", "!", "/", "&" };
          
            if (SPValidate.FrmSPValidate.validateRichAllControls(this) == true)
            {
                MessageBox.Show("通过");
            }
            else
            {
                MessageBox.Show("有特殊字符!");
            }
            // 或者之定义特殊字符
            if (SPValidate.FrmSPValidate.validateTextBox(arr, this) == true)
            {
                MessageBox.Show("通过");
            }
            else
            {
                MessageBox.Show("有特殊字符!");
            }

使用方法,首先将这个控件引用到你的项目里面。然后就直接调用里面的方法。

1
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics