简体   繁体   中英

How to implement Button_Click event handler to a custom control?

I'm trying to create behaviour of my button. I checked solutions on other stackoverflow's problems. I don't know where I made a mistake. Here is the code:

class StartButton : Button
{
    public StartButton() : base()
    {
        this.Location = new Point(100, 100);
        this.Visible = true;
        this.Size = new Size(200, 50);
        this.Click += StartButton_Click;
    }
    void StartButton_Click(object sender, RoutedEventArgs e)
    {

    }
}

Visual returns 2 errors: 1)No overload for 'StartButton_click' matches delegate 'EventHandler' 2)The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?)

I'll be grateful for any solution

this:

void StartButton_Click(object sender, RoutedEventArgs e)
{

}

should be:

void StartButton_Click(object sender, EventArgs e)
{

}

Just change RoutedEventArgs to EventArgs

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM