C# 的 TextBox 控制項預設是沒有 Ctrl+A 可以全選的設計
所以只好一切都自己來了!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public mainForm() { /* 設定雙擊及 Ctrl+A 可全選 TextBox 控制項內的所有文字 */ foreach (Control c in this .groupBox1.Controls) { if (c is TextBox) { c.KeyDown += new KeyEventHandler(allTextBox_KeyDown); c.DoubleClick += new EventHandler(allTextBox_DoubleClick); } } } /* 按下 Ctrl+A 全選文字 */ private void allTextBox_KeyDown( object sender, KeyEventArgs e) { if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A) ((TextBox)sender).SelectAll(); } /* 雙擊全選文字 */ private void allTextBox_DoubleClick( object sender, EventArgs e) { ((TextBox)sender).SelectAll(); } |
沒有留言:
張貼留言