Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;         Controls.Add(tbUsername);     } } 

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 Ctrl+A 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).

like image 913
Patrik Lippojoki Avatar asked Apr 24 '13 16:04

Patrik Lippojoki


People also ask

What is editable TextBox in visual basic?

The TextBox control is generally used for editable text, although it can also be made read-only. Text boxes can display multiple lines, wrap text to the size of the control, and add basic formatting. The TextBox control allows a single format for text displayed or entered in the control.

What is the use of TextBox control?

Typically, a TextBox control is used to display, or accept as input, a single line of text. You can use the Multiline and ScrollBars properties to enable multiple lines of text to be displayed or entered.

What is TextBox in C sharp?

A text box object is used to display text on a form or to get user input while a C# program is running. In a text box, a user can type data or paste it into the control from the clipboard. For displaying a text in a TextBox control , you can code like this.


1 Answers

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.

like image 167
jltrem Avatar answered Oct 06 '22 23:10

jltrem