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

后端 未结 9 2413
春和景丽
春和景丽 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:14

    Like other answers indicate, Application.EnableVisualStyles() should be called. Also the TextBox.ShortcutsEnabled should be set to true. But if your TextBox.Multiline is enabled then Ctrl+A will not work (see MSDN documentation). Using RichTextBox instead will get around the problem.

    0 讨论(0)
  • 2020-12-15 03:17

    Quick answer is that if you are using multiline true you have to explicitly call the select all.

    private void tbUsername_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.A && e.Control)
        {
            tbUsername.SelectAll();
        }
    }
    
    0 讨论(0)
  • 2020-12-15 03:17

    Textbox has a method SelectAll() and worked well for me. (.net 4.5)

    0 讨论(0)
提交回复
热议问题