Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the CTRL+A shortcut disabled on Multiline-enabled TextBox controls in C#?

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?

like image 476
Taylor Lopez Avatar asked Mar 14 '23 21:03

Taylor Lopez


2 Answers

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".

like image 57
Kaitlyn Avatar answered Mar 18 '23 08:03

Kaitlyn


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.

like image 39
xpda Avatar answered Mar 18 '23 08:03

xpda