有关TextBox中输入字符控制的一种解决办法
点击次数:28 次 发布日期:2008-11-26 11:51:30 作者:源代码网
|
源代码网推荐 源代码网推荐 源代码网推荐 private System.Windows.Forms.TextBox textBox1; 源代码网推荐 private string text; 源代码网推荐 public Form1() 源代码网推荐 { 源代码网推荐 text = textBox1.Text; 源代码网推荐 } 源代码网推荐 private void textBox1_TextChanged(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 int len = text.Length; 源代码网推荐 if(len < textBox1.Text.Length) 源代码网推荐 { 源代码网推荐 int index = textBox1.Text.IndexOf(text); 源代码网推荐 char c = (textBox1.Text.Remove(index,text.Length))[0]; 源代码网推荐 if(c.CompareTo("0") < 0||c.CompareTo("9") >0) 源代码网推荐 { 源代码网推荐 textBox1.Text = text; 源代码网推荐 textBox1.SelectionStart = text.Length; 源代码网推荐 } 源代码网推荐 } 源代码网推荐 text = textBox1.Text; 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 源代码网推荐 做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
