Saturday, October 22, 2011

Select all text using ctrl + A in a TextField (multiline) C#

This is quite simple .... just add the keyDown event like below:

this.txtField.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtField_KeyDown);

You should add this event for those textfield only where you want to add this functionality ... Now just add below simple code and enjoy select all feature :D

private void txtField_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && (e.KeyCode == Keys.A))
{
((TextBox)sender).SelectAll();
e.SuppressKeyPress = true;
e.Handled = true;
}

}

Try and enjoy :)

No comments:

PC Magazine Tips and Solutions

PC World: Latest Technology News

PCWorld.com - Most Popular Downloads of the Week