/*
I have problems detecting the Arrow Keys on a User Control. A control
derived from System.Windows. Forms.Control neglects 'bare' Arrow Keys
but does react on the combination <Altor <Ctrl+ Arrow Key. The code
below shows what I mean. How can I cure this? (excuse me for the line
breaks)
*/
//class KeyTest
class KeyTest:System. Windows.Forms.C ontrol
{
//data member label
System.Windows. Forms.Label label=new System.Windows. Forms.Label();
//constructor
KeyTest()
{
Controls.Add(la bel);
KeyDown+=OnKeyD own;
Text="Arrow Keys are Special?";
label.Text="\nP ress <1>...";
Dock=System.Win dows.Forms.Dock Style.Fill;
label.Dock=Syst em.Windows.Form s.DockStyle.Fil l;
}
//OnKeyDown
void OnKeyDown(objec t a,System.Window s.Forms.KeyEven tArgs b)
{
switch(b.KeyCod e)
{
case System.Windows. Forms.Keys.D1:
label.Text+="\n You pressed 1."+
"\n\nNow hold down <Altor <Ctrland press the Arrow Up Key...";
break;
case System.Windows. Forms.Keys.Up:
label.Text+="\n You pressed the Arrow Up Key."+
"\n\nNow release <Altor <Ctrland press the Arrow Up Key
again..."+
"\n\nIt doesn't work!"+
"\nPress <Escor <Spaceto Quit";
break;
case System.Windows. Forms.Keys.Esca pe:
System.Windows. Forms.Applicati on.Exit();
break;
case System.Windows. Forms.Keys.Spac e:
System.Windows. Forms.Applicati on.Exit();
break;
}
}
//Main
[System.STAThrea d]
static void Main()
{
System.Windows. Forms.Form form=new System.Windows. Forms.Form();
form.Controls.A dd(new KeyTest());
System.Windows. Forms.Applicati on.Run(form);
}
}
I have problems detecting the Arrow Keys on a User Control. A control
derived from System.Windows. Forms.Control neglects 'bare' Arrow Keys
but does react on the combination <Altor <Ctrl+ Arrow Key. The code
below shows what I mean. How can I cure this? (excuse me for the line
breaks)
*/
//class KeyTest
class KeyTest:System. Windows.Forms.C ontrol
{
//data member label
System.Windows. Forms.Label label=new System.Windows. Forms.Label();
//constructor
KeyTest()
{
Controls.Add(la bel);
KeyDown+=OnKeyD own;
Text="Arrow Keys are Special?";
label.Text="\nP ress <1>...";
Dock=System.Win dows.Forms.Dock Style.Fill;
label.Dock=Syst em.Windows.Form s.DockStyle.Fil l;
}
//OnKeyDown
void OnKeyDown(objec t a,System.Window s.Forms.KeyEven tArgs b)
{
switch(b.KeyCod e)
{
case System.Windows. Forms.Keys.D1:
label.Text+="\n You pressed 1."+
"\n\nNow hold down <Altor <Ctrland press the Arrow Up Key...";
break;
case System.Windows. Forms.Keys.Up:
label.Text+="\n You pressed the Arrow Up Key."+
"\n\nNow release <Altor <Ctrland press the Arrow Up Key
again..."+
"\n\nIt doesn't work!"+
"\nPress <Escor <Spaceto Quit";
break;
case System.Windows. Forms.Keys.Esca pe:
System.Windows. Forms.Applicati on.Exit();
break;
case System.Windows. Forms.Keys.Spac e:
System.Windows. Forms.Applicati on.Exit();
break;
}
}
//Main
[System.STAThrea d]
static void Main()
{
System.Windows. Forms.Form form=new System.Windows. Forms.Form();
form.Controls.A dd(new KeyTest());
System.Windows. Forms.Applicati on.Run(form);
}
}
Comment