4

MSDN's documentation for the TextBox's ShortcutsEnabled property states that:

The TextBox control does not support the CTRL+A shortcut key when the Multiline property value is true.

... but why? Kaitlyn has mentioned below that both the TextBox and the RichTextBox derive from the same base class TextBoxBase, and yet the RichTextBox control supports the shortcut natively.

It's easy enough to add it back in manually, and there's plenty of questions answer how to do this, but I can't think of why they would go out of their way to disable this feature in this specific circumstance.

What are the technical reasons?

Taylor Lopez
  • 813
  • 1
  • 8
  • 28
  • 1
    This is actually quite an intriguing question... There is a very similar question like yours, at http://stackoverflow.com/questions/5885739/why-are-some-textboxes-not-accepting-control-a-shortcut-to-select-all-by-defau , but most likely the answer there is not the one you seek. – Kaitlyn Sep 03 '15 at 17:30
  • 1
    @Kaitlyn yeah, I saw this question too. It's kind of what started this whole thought process lol. – Taylor Lopez Sep 03 '15 at 17:34
  • 2
    This happened too long ago, you can only get guesses. It never used to have that shortcut, afaik it was added in Win95. Tinkering with the behavior of standard controls is very, very risky. They probably skipped it for multi-line EDIT controls because there were too many programs around that used it as text editor. And thus already having its own shortcut keystrokes. Notepad being the canonical example. – Hans Passant Sep 03 '15 at 19:01
  • 1
    @HansPassant somehow I think you should have submitted that as an answer instead, as it seems to answer it better, and more concise too, but that's just my opinion XD – Kaitlyn Sep 03 '15 at 19:23
  • 2
    You may want to edit this question a little to make it less of an opinion based answer. Ask specifically if there is a technical reason. It's implied by your question but making it more explicit will keep people from closing the question. – James McMahon Sep 04 '15 at 02:23

2 Answers2

4

To quote someone else on SO, it is:

probably because TextBox wraps the native Windows EDIT control, which only supports a subset of the shortcuts.

Quoted from Frédéric Hamidi at https://stackoverflow.com/a/5893879/3472690

After some research, it seems that the native Windows edit control that Frédéric mentions is this one, at MSDN, regarding Edit Controls.

And as Alan Macdonald says in a comment to that very same answer linked above...

Terrible feature of multiline text boxes

EDIT:

Found another potential reason. As quoted from DMA57361 of SuperUser,

As a shortcut, Ctrl+A = Select All is not something implemented by Windows.

It will only work in those programs that implement this shortcut themselves, not universally across the system.

An additional comment to DMA57361's answer by KCotreau of SuperUser also corresponds with what xpda said about compatibility (names removed from the quote):

it is not implemented in XP or Server 2003, but it is implemented in Windows 7 and Server 2008 (and probably Vista), at least for the Run box. So your system does not technically have a problem...it just lacks a feature.

As for more information from MSDN themselves, and which corresponds with the other quotes above... the "About Edit Controls" article says that:

Rich edit controls support many features not available in system edit controls. For more information, see Rich Edit Controls.

Additionally, there are limits on edit controls, as they are, as quoted from this article, also from MSDN (but the Developer Network section rather than the Windows Dev Center, which I'm not sure what difference that makes...)

Edit controls were designed to enter, display, and edit small amounts of text. They were not meant to be the basis for large-scale text editors.


It also, as xpda said, seems to have been very well intended to act like so, or they simply didn't want to bother fixing it, as quoted by a reply to an issue regarding multiline textboxes not supporting the Select-All shortcut on the Visual Studio feedback section:

We have evaluated the issue that you have reported and at this point in the product's lifecycle, it does not meet the criteria to be addressed. This evaluation is carefully done and considers many aspects including the cost of the fix, implications of the change, and the number of reported instances of the issue.

And finally, to further explain why this is by design... and why it would be for "compatility"... there is this quote from a Shuja Ali on a certain CodeGuru forum, saying:

It never used to work in VB 6.0 and .NET 1.1

To further "support" the quote from Shuja Ali, the TextBoxBase.ShortcutEnabled Property is new for .NET Framework 2.0, and the Ctrl+A shortcut already doesn't work at that stage, as evident by the comment by a hemantpurkar to that article.


Therefore, to condense all the above research into a single sentence...

The inability to use the shortcut "Ctrl+A" has existed since the very first version of the .NET Framework where shortcuts are supported properly (2.0), and Microsoft has been too lazy to fix it ever since, thus it is claimed to be "by design" and left like that for "compatibility".

Community
  • 1
  • 1
Kaitlyn
  • 791
  • 1
  • 10
  • 28
  • I suppose it would make sense if it's simply an unimplemented method, but it seems uncharacteristic of the .NET library, which seems to think of everything most of the time. – Taylor Lopez Sep 03 '15 at 17:38
  • @iAmMortos The answer to why it seems uncharacteristic, I think xpda's answer answers that :) aka (backward) compatibility – Kaitlyn Sep 03 '15 at 17:39
  • 1
    @iAmMortos I couldn't find the exact source xpda mentioned, but I believe I have enough research to (almost) fully elaborate on why that shortcut is "disabled" for multiline textboxes. – Kaitlyn Sep 03 '15 at 18:27
3

The official answer is that it's "by design." Probably this was done to maintain compatibility once a long time ago. You can use a RichTextBox to get all the shortcuts by default, including Ctrl-A.

xpda
  • 15,585
  • 8
  • 51
  • 82
  • Do you have a source for this? – Taylor Lopez Sep 03 '15 at 17:39
  • I'm also trying to find a source that references that, but so far, nothing. I did find out that textbox and richtextbox both derive from a common control, called "TextboxBase" (https://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase(v=vs.110).aspx), however. Maybe it's something to do with TextboxBase, that results in Textbox itself not supporting it? – Kaitlyn Sep 03 '15 at 17:45
  • If they both derive from the same base class, and only one supports the shortcut, then it obviously _must_ have been a conscious decision made... I just... I just don't get it >. – Taylor Lopez Sep 03 '15 at 17:49
  • @iAmMortos Neither do I, but I found another reason provided by someone on a different community of StackExchange (which StackOverflow is part of) – Kaitlyn Sep 03 '15 at 17:50
  • @iAmMortos Found an issue ticket raised by someone regarding this particular issue, but it seems to be as xpda said, for Microsoft closed that ticket saying they won't fix it... (more info in my updated answer) – Kaitlyn Sep 03 '15 at 18:18