基本介绍
文本控件,提供多行文本编辑和密码字符掩码功能。
常设置属性
ForeColor:此组件的前景色,用于显示文本;
BorderStyle:指示编辑控件是否应带有边框或边框类型;
Lines:多行编辑中的文本行,作为字符串值的数组;
MaxLength:指定可以在编辑控件中输入的最大字符数;
PasswordChar:指示将为单行编辑控件的密码输入显示的字符;
Multiline:控制编辑控件的文本是否能够跨越多行;
ScrollBars:定义控件滚动条的行为;
WordWrap:指示多行编辑控件是否自动换行;
Enabled:指示是否启用该控件,true为启用状态用户可编辑,false为禁用状态用户不可编辑;
Name:指示代码中用来标识该对象的名称;
Text:获取或设置多格式文本框中的文本;
事例举例
相关代码
//控件提示信息变量 string strUser = "长度不低于四个字符", strPwd = "长度不低于六个字符,由字母和数字组成"; #region 用户密码控件设置提示信息相关事件 private void txt_user_Enter(object sender, EventArgs e) { TextBox tb = (TextBox)sender; if (tb.Text.Equals(strUser)) { tb.Text = string.Empty; tb.ForeColor = System.Drawing.SystemColors.WindowText; } } private void txt_user_Leave(object sender, EventArgs e) { TextBox tb = (TextBox)sender; if (string.IsNullOrWhiteSpace(tb.Text)) { tb.Text = strUser; tb.ForeColor = System.Drawing.SystemColors.ScrollBar; } } private void txt_pwd_Enter(object sender, EventArgs e) { TextBox tb = (TextBox)sender; if (tb.Text.Equals(strPwd)) { tb.Text = string.Empty; tb.ForeColor = System.Drawing.SystemColors.WindowText; tb.PasswordChar = '*'; } } private void txt_pwd_Leave(object sender, EventArgs e) { TextBox tb = (TextBox)sender; if (string.IsNullOrWhiteSpace(tb.Text)) { tb.Text = strPwd; tb.ForeColor = System.Drawing.SystemColors.ScrollBar; tb.PasswordChar = '