首页 > Windows开发 > 详细

C# textBox用法总结

时间:2015-01-08 13:21:05      阅读:414      评论:0      收藏:0      [点我收藏+]

textBox用法总结:

1 去掉边框 【注:this = textBox】
this.BorderStyle = System.Windows.Forms.BorderStyle.None;
2 设置字体 
this.Font = new System.Drawing.Font(this.Font.Name, 11);
3 设置光标
this.Focus();//光标移动到当前textBox中
this.SelectAll(); //选中所有内容
this.SelectionStart = this.Text.Length;///设置光标在末尾 
4 设置大小
this.Size = new System.Drawing.Size(30, 25);
5 设置最大字符个数
this.MaxLength = 3; //最大为3个
6 添加控件,设置控件位置
Label  lb =  new Label();
this.Controls.Add(lb);//添加一个Label
lb.Location = new System.Drawing.Point(10,10);
7 设置字体居中
this.TextAlign = HorizontalAlignment.Center;
8 控制输入内容 --- 重写textBox事件
protected override void OnKeyPress(KeyPressEventArgs e)
{
    //阻止键盘输入e.KeyChar.ToString()按键字符
    e.Handled = true;
    if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar == (char)8))
    {
     //只能输入0 -9
     e.Handled = false;
     return ;
    }
}


C# textBox用法总结

原文:http://blog.csdn.net/taoerit/article/details/42523413

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!