新文章

2010年8月19日 星期四

[C#] TextBox 如何輸入轉大寫、小寫,限制輸入相關code(二)

C# Winform通常在TextBox會依照個人需求,而需要限制使用者輸入數字,英文(大小寫),這裡談的是如何使輸入自動轉大小寫,或者限制輸入大寫。



輸入自動轉大小寫有2個方法


1.手動去更改code,使用事件TextChanged  輸入如下程式碼:
private void textBox1_TextChanged(object sender,System.EventArgs e)   
  {   
  this.textBox1.Text=this.textBox1.Text.ToUpper();   //轉大寫
  /* this.textBox1.Text=this.textBox1.Text.ToLower();   //轉小寫 */
  this.textBox1.SelectionStart=this.textBox1.Text.Length;   
  }

2.使用屬性
可以把TextBox的CharacterCasing属性改為Upper即可實現自動轉大寫。
Lower改小寫,Normal是預設直。





沒有留言:

張貼留言