我正在尝试从数据文件和列表框中删除一行。但我收到错误:'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/