I'm pretty new to C#, and I ran today into a bug.
I'm making a Windows Form Application in Visual C# in Visual Studio 2013. In the "Form1 [Design]" tab of the project, I added a MenuStrip, in which I then created a "New" and "Quit" item.
When I press the "Quit" button (identified here as quitterLapplicationToolStripMenuItem, automatically generated by VS2013) I have this code to run :
private void quitterLapplicationToolStripMenuItem_Click(object sender, CancelEventArgs c, EventArgs e)
{
DialogResult resultat = MessageBox.Show("Close?" + Environment.NewLine + Environment.NewLine + "Really ? No more notifications ?", "Closing", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (resultat == DialogResult.Yes)
{
MessageBox.Show("Prog stopped correctly", "Quit");
Application.Exit();
}
else
{
c.Cancel = true;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
}
And when I try to run this, an error appears, saying :
No overload for 'quitterLapplicationToolStripMenuItem_Click' matches delegate 'System.EventHandler'
Oh, and here's what line is causing the error :
this.quitterLapplicationToolStripMenuItem.Click += new System.EventHandler(this.quitterLapplicationToolStripMenuItem_Click);
What can I do ? I'm stuck and I have not found anything that could help me (and that I could understand)
Replace:
(object sender, CancelEventArgs c, EventArgs e)
with
(object sender, EventArgs e)
The parameters on the method are not correct: you've got a sort of mish-mash of two different method signatures.
It's either supposed to be:
private void quitterLapplicationToolStripMenuItem_Click(object sender, CancelEventArgs c)
or
private void quitterLapplicationToolStripMenuItem_Click(object sender, EventArgs e)