简体   繁体   English

如何将Button_Click事件处理程序实现到自定义控件?

[英]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. 我检查了其他stackoverflow问题的解决方案。 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?) Visual返回2个错误:1)“ StartButton_click”没有重载与委托“ EventHandler”匹配2)找不到类型或名称空间名称“ RoutedEventArgs”(您是否缺少using指令或程序集引用?)

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 只需将RoutedEventArgs更改为EventArgs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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