Atik Rahman
Atik Rahman

Reputation: 91

Calling timer_tick function give me No overload for 'timer2_Tick' matches delegate 'EventHandler'

I am trying to give a label as flashlight effect. I have created a function called flashlight. Here is some part of the code

public void Flashlight(Label lable)
{
    Random rand = new Random();
    int one = rand.Next(0, 255);
    int two = rand.Next(0, 255);
    int three = rand.Next(0, 255);
    int four = rand.Next(0, 255);

    lable.ForeColor = Color.FromArgb(one, two, three, four);
}

public Form1()
{
    InitializeComponent();
    pictureBox2.Size = new Size(82, 82);
    pictureBox3.Size = new Size(82, 82);
    pictureBox3.Enabled = false;
    timer2.Tick += (sender, args) => timer2_Tick(sender, args, label1);
}

private void timer2_Tick(object sender, EventArgs e,Label l)
{
    Flashlight(l);
}

Can anyone tell me what I am missing here ? this is the part of code where I am stuck in. I am getting error

CS0123 No overload for 'timer2_Tick' matches delegate 'EventHandler'

Upvotes: 1

Views: 118

Answers (1)

Salah Akbari
Salah Akbari

Reputation: 39966

Search for timer2_Tick in somewhere else in your code, it should be inside Form1.Designer.cs and then delete it, that's because you've already declared it by double clicking on your timer. So you need to delete the following line after you've found it:

this.timer2.Tick += new System.EventHandler(this.timer2_Tick);

As a shorter way, to find this line, after you've rebuilt your project and then in the Error List window double click on error which says:

CS0123 No overload for 'timer2_Tick' matches delegate 'EventHandler'

And then delete that line.

Upvotes: 2

Related Questions