本文共 2920 字,大约阅读时间需要 9 分钟。
随着项目的深入,我一直想为项目开发一套高质量的自定义控件,最终有了这篇关于自定义文本框控件的实现方案。
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
如果觉得写的还行,请点个 star 支持一下吧
终于到文本框了,文本框将包含原文本框扩展,透明文本框,数字输入文本框,带边框文本框。本文将讲解带边框文本框,可选弹出键盘样式,继承自控件基类UCControlBase。同时用到了无焦点窗体和键盘,如果你还没有了解,请前往查看。
添加用户控件,命名UCTextBoxEx,继承自UCControlBase。
下面是该控件的主要属性:是否显示清理按钮
public bool IsShowClearBtn { get { return m_isShowClearBtn; } set { m_isShowClearBtn = value; if (value) { btnClear.Visible = !(txtInput.Text == "\r\n") && !string.IsNullOrEmpty(txtInput.Text); } else { btnClear.Visible = false; } } }是否显示查询按钮
public bool IsShowSearchBtn { get { return m_isShowSearchBtn; } set { m_isShowSearchBtn = value; btnSearch.Visible = value; } }键盘打开样式
public KeyBoardType KeyBoardType { get { return keyBoardType; } set { keyBoardType = value; } }字体
public new Font Font { get { return this.txtInput.Font; } set { this.txtInput.Font = value; } }输入类型
public TextInputType InputType { get { return txtInput.InputType; } set { txtInput.InputType = value; } }水印文字
public string PromptText { get { return this.txtInput.PromptText; } set { this.txtInput.PromptText = value; } }水印字体
public Font PromptFont { get { return this.txtInput.PromptFont; } set { this.txtInput.PromptFont = value; } }水印颜色
public Color PromptColor { get { return this.txtInput.PromptColor; } set { this.txtInput.PromptColor = value; } }正则表达式
public string RegexPattern { get { return this.txtInput.RegexPattern; } set { this.txtInput.RegexPattern = value; } }最大值
public decimal MaxValue { get { return this.txtInput.MaxValue; } set { this.txtInput.MaxValue = value; } }最小值
public decimal MinValue { get { return this.txtInput.MinValue; } set { this.txtInput.MinValue = value; } }小数位数
public int DecLength { get { return this.txtInput.DecLength; } set { this.txtInput.DecLength = value; } }文本改变事件
public new event EventHandler TextChanged { add: TextChanged += new EventHandler(TextChangedHandler); remove: TextChanged -= new EventHandler(TextChangedHandler); }键盘按钮点击事件
public event EventHandler KeyboardClick { add: KeyboardClick += new EventHandler(KeyboardClickHandler); remove: KeyboardClick -= new EventHandler(KeyboardClickHandler); }查询按钮点击事件
public event EventHandler SearchClick { add: SearchClick += new EventHandler(SearchClickHandler); remove: SearchClick -= new EventHandler(SearchClickHandler); }这套文本框控件具有以下功能:
如果你觉得这篇文章写得还行,请点个 star 支持一下吧。
欢迎前来交流探讨:转载地址:http://hfvkz.baihongyu.com/