c# - "button_click"没有重载匹配委托(delegate) 'System.EventHandler'

标签 c# button

我正在尝试从数据文件和列表框中删除一行。但我收到错误:'removeButton_Click' 的重载不匹配委托(delegate) 'System.EventHandler'。我该如何解决这个错误?

public partial class Message_ReaderMainForm : Form
{
private void validSitesListBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        removeButton.Visible = true;
        moveButton.Visible = true;
        editButton.Visible = true;

        removeButton_Click(sender, e, validSitesListBox.SelectedIndex);
    }

    private void removeButton_Click(object sender, EventArgs e, int location)
    {
        StreamWriter file = new StreamWriter("userFile.txt");

        validSitesListBox.Items.RemoveAt(location);
        data.RemoveAt(location);

        for (int i = 0; i < data.Count(); i++)
        {
            file.WriteLine(data[i].Item1 + " " + data[i].Item2 + " " + data[i].Item3);
        }

    }

}

这是错误发生的位置:

 partial class Message_ReaderMainForm
{
        // 
        // removeButton
        // 
        this.removeButton.Location = new System.Drawing.Point(255, 351);
        this.removeButton.Margin = new System.Windows.Forms.Padding(2);
        this.removeButton.Name = "removeButton";
        this.removeButton.Size = new System.Drawing.Size(59, 21);
        this.removeButton.TabIndex = 5;
        this.removeButton.Text = "Remove";
        this.removeButton.UseVisualStyleBackColor = true;
    // This is where the error is showing up in the code.
        this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
}

最佳答案

这是因为你声明了它

private void removeButton_Click(object sender, EventArgs e, int location)

int location 参数表示它与 System.EventHandler 委托(delegate)定义不匹配。如果您想将其用作事件处理程序并通过其他方式获取 location,则需要删除该参数。

关于c# - "button_click"没有重载匹配委托(delegate) 'System.EventHandler',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30531611/

相关文章:

html - 如何创建带有图标和按钮描述文本的链接按钮

asp.net - 如何在 vb 中创建警报弹出消息?

c# - XNA、DirectX 和 Monogame、SharpDX 之间的区别

c# - 在 C# 中获取 "Unterminated [] set."错误

c# - 自定义 Visual Studio 错误

c# - 如何计算 C# 数组列表的滚动平均值?

c# - 与 LAN 上的应用程序通信

java - 编写按钮方法时出错

css - 两列独立的按钮

button - 在 Twitter Bootstrap 中更改 btn-group .active 样式