本文介绍了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

推荐答案


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,用于选择文本框中的所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:29