using System; using System.Collections.Generic; using System.Text; namespace Tigers_WindowsControlLibrary.Windows ... { class TextBox_Validate_ListBox_DropDownEdit : System.Drawing.Design.UITypeEditor ...{ public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) ...{ if (context != null && context.Instance != null) ...{ return System.Drawing.Design.UITypeEditorEditStyle.DropDown; } return base.GetEditStyle(context); } public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) ...{ System.Windows.Forms.Design.IWindowsFormsEditorService editorService = null; if (context != null && context.Instance != null && provider != null) ...{ editorService = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService)); if (editorService != null) ...{ TextBox_Validate textBox_Validate = (TextBox_Validate)context.Instance; Tigers_WindowsControlLibrary.PulicControl.TextBox_Validate_ListBox textBox_Validate_ListBox = new Tigers_WindowsControlLibrary.PulicControl.TextBox_Validate_ListBox(textBox_Validate.ValidateString); editorService.DropDownControl(textBox_Validate_ListBox); value = textBox_Validate_ListBox.ValidateString; return value; } } return value; } }}
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; namespace Tigers_WindowsControlLibrary.PulicControl ... { partial class TextBox_Validate_ListBox : System.Windows.Forms.UserControl ...{ public TextBox_Validate_ListBox() ...{ InitializeComponent(); } private string _validateString = string.Empty; public string ValidateString ...{ get ...{ return _validateString; } set ...{ _validateString = value; } } public TextBox_Validate_ListBox(string validateString) ...{ InitializeComponent(); this._validateString = "validateString"; switch (validateString) ...{ case @"w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*":this.ListBox_Select.SelectedIndex = 0; break; case @"[a-zA-z]+://[^s]*": this.ListBox_Select.SelectedIndex = 1; break; case @"d+.d+.d+.d+": this.ListBox_Select.SelectedIndex = 2; break; case @"[1-9][0-9]{4,}": this.ListBox_Select.SelectedIndex = 3; break; case @"[1-9]d{5}(?!d)": this.ListBox_Select.SelectedIndex = 4; break; case @"^((d{3,4}-)|d{3.4}-)?d{7,8}$": this.ListBox_Select.SelectedIndex = 5; break; case @"d{15}|d{18}": this.ListBox_Select.SelectedIndex = 6; break; case @"[一-龥]": this.ListBox_Select.SelectedIndex = 7; break; //以字母开头,长度在6~18之间,只能包含字符、数字和下划线。 case @"^[a-zA-Z]w{5,17}$": this.ListBox_Select.SelectedIndex = 8; break; case @"^[a-zA-Z][a-zA-Z0-9_]{4,15}$": this.ListBox_Select.SelectedIndex = 9; break; case @"<(S*?)[^>]*>.*?</>|<.*? />": this.ListBox_Select.SelectedIndex = 10; break; case @"^-?[1-9]d*$": this.ListBox_Select.SelectedIndex = 11; break; case @"^[1-9]d*$": this.ListBox_Select.SelectedIndex = 12; break; case @"^-[1-9]d*$ ": this.ListBox_Select.SelectedIndex = 13; break; case @"^[1-9]d*|0$": this.ListBox_Select.SelectedIndex = 14; break; case @"^-[1-9]d*|0$": this.ListBox_Select.SelectedIndex = 15; break; case @"^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$": this.ListBox_Select.SelectedIndex = 16; break; case @"^[1-9]d*.d*|0.d*[1-9]d*$": this.ListBox_Select.SelectedIndex = 17; break; case @"^-([1-9]d*.d*|0.d*[1-9]d*)$": this.ListBox_Select.SelectedIndex = 18; break; case @"^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$": this.ListBox_Select.SelectedIndex = 19; break; case @"^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$": this.ListBox_Select.SelectedIndex = 20; break; case @"^[A-Za-z]+$": this.ListBox_Select.SelectedIndex = 21; break; case @"^[A-Z]+$": this.ListBox_Select.SelectedIndex = 22; break; case @"^[a-z]+$": this.ListBox_Select.SelectedIndex = 23; break; case @"^[A-Za-z0-9]+$": this.ListBox_Select.SelectedIndex = 24; break; case @"^w+$": this.ListBox_Select.SelectedIndex = 25; break; default: this.ListBox_Select.SelectedIndex = 26; break; } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) ...{ switch (this.ListBox_Select.SelectedItem.ToString().Trim()) ...{ case "E-mail----------": this._validateString = @"w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*"; break; case "URL-Http": this._validateString = @"[a-zA-z]+://[^s]*"; break; case "IP地址": this._validateString = @"d+.d+.d+.d+"; break; case "QQ": this._validateString = @"[1-9][0-9]{4,}"; break; case "邮编": this._validateString = @"[1-9]d{5}(?!d)"; break; case "电话号": this._validateString = @"^((d{3,4}-)|d{3.4}-)?d{7,8}$"; break; case "身份证": this._validateString = @"d{15}|d{18}"; break; case "中文": this._validateString = @"[一-龥]"; break; //以字母开头,长度在6~18之间,只能包含字符、数字和下划线。 case "密码": this._validateString = @"^[a-zA-Z]w{5,17}$"; break; case "帐号": this._validateString = @"^[a-zA-Z][a-zA-Z0-9_]{4,15}$"; break; case "HTML标记": this._validateString = @"<(S*?)[^>]*>.*?</>|<.*? />"; break; case "整型-----------": this._validateString = @"^-?[1-9]d*$"; break; case "正整数": this._validateString = @"^[1-9]d*$"; break; case "负整数": this._validateString = @"^-[1-9]d*$ "; break; case "非负整数": this._validateString = @"^[1-9]d*|0$"; break; case "非正整数": this._validateString = @"^-[1-9]d*|0$"; break; case "浮点数--------": this._validateString = @"^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$"; break; case "正浮点数": this._validateString = @"^[1-9]d*.d*|0.d*[1-9]d*$"; break; case "负浮点数": this._validateString = @"^-([1-9]d*.d*|0.d*[1-9]d*)$"; break; case "非负浮点数": this._validateString = @"^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$"; break; case "非正浮点数": this._validateString = @"^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$"; break; case "英文--------------": this._validateString = @"^[A-Za-z]+$"; break; case "英文(大写)": this._validateString = @"^[A-Z]+$"; break; case "英文(小写)": this._validateString = @"^[a-z]+$"; break; case "数字和英文": this._validateString = @"^[A-Za-z0-9]+$"; break; case "数字和英文或下划线": this._validateString = @"^w+$"; break; } this.ProcessDialogKey(Keys.Enter); //; } private void Bt_Close_Click(object sender, EventArgs e) ...{ this.ProcessDialogKey(Keys.Enter); // this.Dispose(); } }}