The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,949 other followers

Archive for December 4th, 2012

.NET/C#/WinForms: small code snippet to enable Ctrl-A for select all in a single/multi-line TextBox

Posted by jpluimers on 2012/12/04

WinForms does not automatically enable Ctrl-A as “Select All” action.

The below code snippet works when you bind it to the KeyDown event of a TextBox (actually the event is on Control).

The e.SuppressKeyPress = true suppresses the bell sound in a multiline TextBox, as e.Handled = true won’t.

        private void textBox_KeyDown_HandleCtrlAToSelectAllText(object sender, KeyEventArgs e)
            TextBox textBox = sender as TextBox;
            if (null != textBox)
                if (e.Control && e.KeyCode == Keys.A)
                    e.SuppressKeyPress = true;


Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

%d bloggers like this: