I am wanting to put Event KeyDown for when the user. Click on one button of the KeyBoard, and it will do something.
But It's not working, it says that my Form does not contain a definition for the button(btnCalc_Click) and no method extension .
My code is :
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (btnLimpar.Enabled)
{
btnLimpar.PerformClick();
}
else
{
this.btnLimpar_Click(null, new EventArgs());
}
}
if (e.KeyCode == Keys.End)
{
if (btnCalcular.Enabled)
{
btnCalcular.PerformClick();
}
else
{
this.btnCalcular_Click(null, new EventArgs());
}
}
}
It get's wrong in the code : this.btnCalcular_Click(null, new EventArgs());
Error: FormularioHospital.Form1' does not contain a definition for 'btnCalcular_Click' and no extension method 'btnCalcular_Click' accepting a first argument of type 'FormularioHospital.Form1' could be found. `
Option 1:
Go to designer and simply double click on your button. it will create that method for you.
Option 2:
Create this method, then using designer, assign that method to click event of your button.
private void btnCalcular_Click(object sender, EventArgs e)
{
// codes that you want execute when your button clicked
}
btnCalcular
It will create the necessary procedure for you.
btnCalcular
and Paste this code on your code behind
private void btnCalcular_Click(object sender, EventArgs e)
{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.