Code
using System ;
using ;
using ;
using ;
using ;
using ;
public class Form1 : Form
{
private components = null ;
public Form1 ( )
{
file://initializes various components in the form
InitializeComponent ( ) ;
}
protected override void Dispose ( bool disposing )
{
file://clear resources used in the program
if ( disposing )
{
if ( components != null )
{
( ) ;
}
}
( disposing ) ;
}
private void InitializeComponent ( )
{
= new ( 6 , 14 ) ;
= new ( 292 , 273 ) ;
= "Form1" ;
= "C# handles keyboard events!";
file://Define an event processing process "Form1_KeyUp" for the key press
+= new KeyEventHandler ( this.Form1_KeyUp ) ;
}
static void Main ( )
{
( new Form1 ( ) ) ;
}
file://displays the name of the key you pressed
private void Form1_KeyUp ( object sender , KeyEventArgs e )
{
( ( ) , "The health you press is:" );
}
}
All of them were found online. After reading it, I tried it myself many times, but the buttons didn't respond...
It was only later found in the book that it was necessary to set the KeyPreview property of the corresponding form to true first.
C# =true;+=newKeyEventHandler(frmNewBook_KeyDown);
}voidfrmNewBook_KeyDown(objectsender, KeyEventArgs e)
{switch()
{caseKeys.F4:
("The author will give some points");break;//......}
}