How to write the code to create short cut keys for buttons in c#.net
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
FroglegRank #1,020 · 1.9K reputationPosted Sep 14, 2012, 3:37 AM EDT
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("I'm button 1");
}
private void button2_Click(object sender, EventArgs e)
{
bttnTwo();
}
public void bttnTwo()
{
MessageBox.Show("I'm button 2");
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.A)//2 differnt ways
{
button1.PerformClick();
}
else if (e.KeyCode == Keys.B)
{
bttnTwo();
}
}
}
set form keypreview to true