hi,
I am having a 4 buttons and a textbox on a form in windows application. I am using button keypress event so that when I press on keyboard that appropriate button is triggered and button text should enter in to the text box. I gave focus to all 4 buttons and executed the application but when i press on keyboard, the keypress event is not raising, I also tried by giving select method to all buttons but the last button which I gave the select method is raising for all other buttons also. please help me..
Loading
Kirtan PatelPosted Sep 16, 2009, 6:12 AM
Here is Your Desired Code :)
Dont Forget to mark "Do you like answer" please it will give me some credits :)
dont Forget to Change Form1's KeyPreview Propertie to "True"
then Follow The Code (Code Will type characters in TextBox while Pressing Capital A Capital B and Capital C)
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.A)
{
btnA.PerformClick();
}
else if (e.KeyChar == (char)Keys.B)
{
btnB.PerformClick();
}
else if (e.KeyChar == (char)Keys.C)
{
btnC.PerformClick();
}
}
private void btnA_Click(object sender, EventArgs e)
{
textBox1.Text += btnA.Text;
}
private void btnB_Click(object sender, EventArgs e)
{
textBox1.Text += btnB.Text;
}
private void btnC_Click(object sender, EventArgs e)
{
textBox1.Text += btnC.Text;
}