possible Button and KeyPress conflict
Hi
I'm trying to design a form in c# for PocketPC 2003. All i want it to do is execute different events on a keypress or a button click.
Let say i have a blank form, if you press A, B or C it closes the form (this bit works):
public ABC_Menu()
{
InitializeComponent();
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ABC_Menu_KeyPress);
}
private void ABC_Menu_Load(object sender, EventArgs e)
{
}
private void ABC_Menu_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar.ToString()=="A")
{
close();
}
if(e.KeyChar.ToString()=="B")
{
close();
}
if(e.KeyChar.ToString()=="C")
{
close();
}
}
That works fine. Now if i add some buttons to the form, the buttons work but the keypress doesn't do a thing!
public ABC_Menu()
{
InitializeComponent();
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ABC_Menu_KeyPress);
}
private void ABC_Menu_Load(object sender, EventArgs e)
{
}
private void ABC_Menu_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar.ToString()=="A")
{
close();
}
if(e.KeyChar.ToString()=="B")
{
close();
}
if(e.KeyChar.ToString()=="C")
{
close();
}
}
private void button_a_Click(object sender, EventArgs e)
{
close();
}
private void button_b_Click(object sender, EventArgs e)
{
close();
}
private void button_b_Click(object sender, EventArgs e)
{
close();
}
Can anyone explain why the keypresses aren't working but the buttons are?
Any helps is much appreciated.
Ant