I don't know if the question is foolish, but i do find few textboxes here and there in my own program that accepts Control+A shortcut to select the entire text "by default" with "no coding".
I dunno what additional informations I've to give here as I find absolutely no difference between those textboxes. Those are all simple dragged and dropped textboxes.
Note: I'm not talking about this piece of code:
if (e.Control && e.KeyCode == Keys.A)
{
textBox1.SelectAll();
}
I want selection by default..Or is there anyway to change textbox property so that textboxes accept all default windows shortcuts.
Edit: Everything else (Control + Z
, Control + X
, Control + C
, Control + V
) works by default !!! Why not Control + A
??
Update: The text boxes that accepted Ctrl+A
by default were masked textboxes, not the regular one. And at that point I was with .NET 2.0. But I guess the original problem was something else, as I can see Ctrl+A
working fine by default in .NET 2.0 code.
You might be looking for the ShortcutsEnabled property. Setting it to
true
would allow your text boxes to implement the Ctrl+A shortcut (among others). From the documentation:EDIT:
However, the documentation states:
You will probably have to use another subclass of
TextBoxBase
, such as RichTextBox, for that to work.This answer worked for me in a similar question (which isn't marked as accepted)
Original Post: How can I allow ctrl+a with TextBox in winform?
Make sure that Application.EnableVisualStyles(); is not commented out in static void Main()
That can disable Ctrl+A
Indeed CTRL + A will not work unless you add something like this:
This question wants an answer that cannot be given in the form of code avoidance, as the Win32 API at the core of the other methods doesn't allow it. If other methods DO allow it, they are just writing the code for you. :)
So the real question is: What is the smallest, neatest way to do it? This worked for me:
First, there is no need to handle WM_KEYDOWN! And no need to test for the Ctrl key already down either. I know that most examples here (and CodeProject and many other places) all say there is, but it does not cure the beep that results whenever a WM_CHAR arises that is not handled.
Instead, try handling WM_CHAR and doing the Ctrl+A selection there:
Remember to subclass the EDIT control to this Edit_Prc() using WPA=SetWindowLong(...) where WPA is the window procedure address for CallWindowProc(...)