我试图从数据的文件和一个列表框删除线。但我得到的错误:没有重载“removeButton_Click”匹配委托“System.EventHandler。”我该如何解决这个错误?无过载“button_click”匹配委托“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);
}
this.removeButton.Click + =新System.EventHandler(this.removeButton_Click); //每个事件只能有1个方法。把第二个放在一个函数中,并从事件中调用它。 –
从'removeButton_Click'方法中删除'location'参数 –