我試圖從數據的文件和一個列表框刪除線。但我得到的錯誤:沒有重載「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'參數 –