C#: Test Key Press combination

person Jason Huangfolder_openC#, Codelocal_offer, access_time December 26, 2008

To test Key press combination on a Windows Form. Just create an event for the form (KeyDown), then in the Event Handler code test KeyEventArgs e to see if certain keys are press.

The following code test to see if Ctrl + Alt + T is pressed in FormMain, if so it launch a new form called FrmTest.


private void FormMain_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
   if (e.Modifiers == (System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Alt))
   {
		if(e.KeyCode == System.Windows.Forms.Keys.T)
		{
			System.Windows.Forms.FrmTest aForm = new System.Windows.Forms.FrmTest();
			this.Visible = false;
			aForm.ShowDialog();
			this.Visible = true;
		}
    }
}

Comments

  1. Confirmo. Y con esto me he encontrado. Discutiremos esta pregunta.

  2. resultados del kino tachira

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>