开发者

"Select all" in all textboxes

开发者 https://www.devze.com 2023-02-13 12:59 出处:网络
private void textBox1_MouseClick(object sender, MouseEventArgs e) { textBox1.SelectAll(); } This works but I have 6 textBoxes.Is there any easier way instead of adding event listen开发者_开发技巧ers
private void textBox1_MouseClick(object sender, MouseEventArgs e)
        {
            textBox1.SelectAll();
        }

This works but I have 6 textBoxes. Is there any easier way instead of adding event listen开发者_开发技巧ers for each and every textbox? Or a shorthand or something?

Thanks.


Add the same event handler to each and have ((TextBox)sender).SelectAll() to ensure the one that is clicked on is highlighted.

If you're looking for something more generic create a derived class of TextBox containing the same.

0

精彩评论

暂无评论...
验证码 换一张
取 消