Patrik Lippojoki Patrik Lippojoki - 1 year ago 73
C# Question

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

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 doesn't work for me. I have this code:

public class LoginForm : Form
private TextBox tbUsername;

public LoginForm()
tbUsername = new TextBox();
tbUsername.ShortcutsEnabled = true;
tbUsername.Multiline = false;

The textbox shows up, I can write on it, I can cut, copy and paste text on it without any problems.
But when I try to press
I only hear a "bling" similar to the bling that you hear if you try to erase text from an empty textbox (try it with your browser's address bar).

Answer Source

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.