为什么在C#中启用Multiline的TextBox控件上禁用了CTRL A快捷键?

用于TextBox的ShortcutsEnabled属性的MSDN的documentation声明:

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

… 但为什么? Kaitlyn在下面提到TextBox和RichTextBox都派生自相同的基类TextBoxBase,而RichTextBox控件本身支持该快捷方式.

手动添加它很容易,并且有很多问题可以解答如何执行此操作,但我无法想到为什么他们会在这种特定情况下不再使用此功能.

技术原因是什么?

解决方法:

在SO上引用其他人,它是:

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

引自FrédéricHamidi于https://*.com/a/5893879/3472690

经过一些研究,似乎Frédéric提到的原生Windows编辑控件是this one, at MSDN, regarding Edit Controls.

正如艾伦·麦克唐纳(Alan Macdonald)在对上述相同答案的评论中所说的那样……

Terrible feature of multiline text boxes

编辑:

找到另一个潜在原因.从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.

超级用户的KCotreau对DMA57361的答案的另一个评论也与xpda所说的兼容性(从名称中删除的名称)相对应:

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.

至于来自MSDN本身的更多信息,并且与上面的其他引用相对应……“About Edit Controls”文章说:

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

另外,编辑控件有限制,因为它们是从this article, also from MSDN引用的(但是开发人员网络部分而不是Windows开发人员中心,我不确定它有什么不同……)

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.

正如xpda所说,它似乎也非常适合这样做,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.

最后,为了进一步解释为什么这是设计……以及它为什么会出现“比较”……有一个来自Shuja Ali on a certain CodeGuru forum, saying的引用:

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

为了进一步“支持”Shuja Ali的引用,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.

因此,将所有上述研究浓缩成一句话……

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

上一篇:python – ‘String’模块对象没有属性’join’


下一篇:C#如何将不同按钮的按钮文本设置为同一文本框