c# - No overload for 'button' matches delegate 'EventHandler'; -


this question has answer here:

fairly new using windows forums , im running problem of using intergers on multiple methods, while searching solution changed method

    private void button_click(object sender, eventargs e) 

to this

    public void button_click(object sender, eventargs e, int attack1, int hp2) 

this works fine in view, designer tab giving off error "no overload 'button_click' matches delegate 'eventhandler'. intergers created within constructor of forum. there solution fix problem or there better way use integers between methods

event handler should match signature of delegate - i.e. type , count of parameters , type of return value should same defined event delegate. buttonclick event has type of eventhandler delegate. delegate defined

public delegate void eventhandler(object sender, eventargs e) 

handlers attach event should have same signature - void (object, eventargs).

and if possible use handlers different signatures, have forgotten event raised button instance. how button know value provide additional method parameters? knows nothing attack , hp. , cannot modify button class implementation pass additional arguments you.

if want use additional values in event handler, should store values form fields:

public class form1 : form {    private int attack;    private int hp;     public form1()    {        // initialize attack , hp here    }     private void button_click(object sender, eventargs e)    {        // attack , hp avalilable here    } } 

or can store information in tag property of button , retrieve information event's sender:

   private void button_click(object sender, eventargs e)    {        var button = (button)sender;        // use button.tag    } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -