Ctrl + A,用于选择文本框中的所有文本 [英] ctrl + a for selecting all text in textbox

查看:93
本文介绍了Ctrl + A,用于选择文本框中的所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现可以通过按ctrl + a选择文本框中的所有文本来选择文本框中的所有文本

i have found this for selecting all the text in textbox by pressing ctrl+a for selecting all the text in textbox

private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
             if (e.KeyChar == '\x1')
            {
                ((TextBox)sender).SelectAll();
                e.Handled = true;
            }

        }



但是问题是我的数据输入表单中有很多文本框.所以我想减少代码.我必须为文本框的每个按键事件编写此代码.
我能怎么做?为多个文本框编写一个代码以供选择?
对不起,我的英语不好.



but the problem is i have many textbox in my data entry form. so i want to reduce the code. i have to write this code for every keypress event of textbox.
how can i do? writing one code for many textbox for selecting?
sorry for my bad english

推荐答案

您可以简单地将此处理程序分配给所需的任何TextBox的KeyPress事件.您已经通过转换sender参数完成了艰苦的工作.

不过,有一个问题,您真的需要这样做吗? Ctrl + a可以选择几乎所有地方.
You can simply assign this handler to the KeyPress event of any TextBox you need. You''ve done the hard work by casting the sender parameter.

One question though, do you really need to do this? Ctrl + a is select all just about everywhere..


如果您确实需要处理Ctrl + A,则将文本框的按键事件连接到一个事件处理程序,如下表所示加载.

If you really need to handle the Ctrl+A, you wire key press event of text box to one event handler as shown below in form load.

textBox1.KeyPress += new KeyPressEventHandler(CommonKeyPress);
textBox2.KeyPress += new KeyPressEventHandler(CommonKeyPress);



那么下面的功能应该很好用!



Then your function below should work great !

private void CommonKeyPress(object sender, KeyPressEventArgs e)
{
  if (e.KeyChar == '\x1')
  {
    ((TextBox)sender).SelectAll();
    e.Handled = true;
  }
}



Milind



Milind


public void select all()
{
   if (e.KeyChar == '\x1')
            {
                ((TextBox)sender).SelectAll();
                e.Handled = true;
            }
}

private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
          selectall();
        }

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
          selectall();
        }

private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
        {
          selectall();
        }


这篇关于Ctrl + A,用于选择文本框中的所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆