Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I allow things such as Ctrl-A and Ctrl-Backspace in a C# TextBox

I've got a System.Windows.Forms.TextBox that is multi-line but it doesn't accept commands like Control-A and Control-Backspace.

Control-A does nothing and Control-Backspace inserts a box character.

The "Shortcuts Enabled" property is set to true.

like image 876
JDiPierro Avatar asked Jan 20 '13 21:01

JDiPierro


People also ask

How do I press Ctrl Backspace?

That is, press the Ctrl key and hold it down, and press the Backspace key at the same time.

What does Ctrl a backspace do?

Ctrl+Backspace inserts a small box instead of erasing.


1 Answers

From MSDN on the ShortcutsEnabled property:

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

You'll have to implement it yourself.

Something like this should work:

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control & e.KeyCode == Keys.A)
        {
            textBox1.SelectAll();
        }
        else if (e.Control & e.KeyCode == Keys.Back)
        {
            SendKeys.SendWait("^+{LEFT}{BACKSPACE}");
        }
    }
like image 140
Blachshma Avatar answered Oct 14 '22 09:10

Blachshma