How can I allow ctrl+a with TextBox in winform?

后端 未结 9 2411
春和景丽
春和景丽 2020-12-15 02:38

I\'m asking the question already asked (and even answered) here: Why are some textboxes not accepting Control + A shortcut to select all by default

But that answer d

9条回答
  •  有刺的猬
    2020-12-15 03:07

    This is my code, it is working fine

    private void mainSimPlus_KeyDown(object sender, KeyEventArgs e)
                {
                    e.Handled = true;
                    if (e.Control == true && e.KeyCode == Keys.A)
                    {
                        if (SelectAllTextBox(txt1))
                            return;
                        if (SelectAllTextBox(txt2))
                            return;
                    }
                }
                private bool SelectAllTextBox(TextBox txt)
                {
                    if (txt.Focused)
                    {
                        txt.SelectAll();
                        return true;
                    }
                    else
                        return false;
                }
    

提交回复
热议问题