C.Shoe
C.Shoe

Reputation: 17

No overload for "MainTimer_Tick" matches delegate "System.EventHandler"

I've read many questions here already but I do not know how it could help the game-breaking error I have.

In my Mario game I have the form GameGUI.cs. I have a timer called MainTimer. When I try to run the error

No overload for "MainTimer_Tick" matches delegate "System.EventHandler"

shows up. I do not know what is going on.

//
// MainTimer
//
this.MainTimer.Enabled = true;
this.MainTimer.Interval = 16;
this.MainTimer.Tick += new System.EventHandler(this.MainTimer_Tick);

I have a lot of code for MainTimer_Tick. This is the issue, I think.

private void MainTimer_Tick(object sender, KeyEventArgs e)

Is this the problem?

Upvotes: 0

Views: 1187

Answers (1)

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

You needto have EventArgs instead of KeyEventArgs

Replace This:

private void MainTimer_Tick(object sender, KeyEventArgs e)

With This:

private void MainTimer_Tick(object sender, EventArgs e)

EDIT:

if you want to handle keys on the form (on any control ex:Textbox) you needto handle the KeyDown event of that control as below:

//set the KeyPreview of the Form to true

this.KeyPreview=true;
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
        //code to handle the key down events
}

Upvotes: 1

Related Questions