The Wiert Corner – irregular stream of stuff

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

  • My badges

  • Twitter Updates

    • @martijnmollers Qua afhalen (we wonen in Osdorp, ongeveer een half uur rijden) : welke gerechten zijn dan praktisch? 5 minutes ago
    • @martijnmollers Ik was laatst op zoek waarom "de Woelige Baren" verdwenen was, maar dit lijkt me een meer dan waardig alternatief. 14 minutes ago
    • @sys_adm_ama Nie gewusst das es auf Deutsch auch "Pappenheimer" gibt (: 2 hours ago
    • RT @bslagter: We hebben het al vaak gehad over de ongelijkmatige manier waarop corona zich verspreidt. Clusters, superverspreiding, dispers… 2 hours ago
    • RT @dd_flo: Wer die Weihnachtsmärkte vermisst kann sich vom 28.11. bis zum 24.12. gerne eine Tasse Glühwein für 4 € bei mir am Küchenfenste… 2 hours ago
  • 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,119 other followers

.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)
                {
                    textBox.SelectAll();
                    e.SuppressKeyPress = true;
                }
            }
        }

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: