假设我有 2 个按钮女巫应该执行相同的操作,但在不同的对象上。
目前我正在将所有需要的引用传递给这样的方法:
private void sub1_add_to_db_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(
substanse1, sub1_add_to_db_btn, sub2_add_to_db_btn, sub1_found_in_db_list,
sub2_found_in_db_list, false, sub1_listBox, sub2_listBox);
}
private void sub2_add_to_db_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(
substanse2, sub2_add_to_db_btn, sub1_add_to_db_btn, sub2_found_in_db_list,
sub1_found_in_db_list, false, sub2_listBox, sub1_listBox);
}
我想知道是否有其他更有效的方法来做到这一点。谢谢。
编辑:
这就是我的一些代码的样子,它让我抓狂!!!
private void sub1_add_to_db_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(substanse1, sub1_add_to_db_btn, sub2_add_to_db_btn,
sub1_found_in_db_list, sub2_found_in_db_list, false, sub1_listBox, sub2_listBox);
}
private void sub2_add_to_db_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(substanse2, sub2_add_to_db_btn, sub1_add_to_db_btn,
sub2_found_in_db_list, sub1_found_in_db_list, false, sub2_listBox, sub1_listBox);
}
private void sub1_edit_name_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(substanse1, sub1_add_to_db_btn, sub2_add_to_db_btn,
sub1_found_in_db_list, sub2_found_in_db_list, true, sub1_listBox, sub2_listBox);
}
private void sub2_edit_name_btn_Click(object sender, EventArgs e)
{
Add_Substance_To_Database(substanse2, sub2_add_to_db_btn, sub1_add_to_db_btn,
sub2_found_in_db_list, sub1_found_in_db_list, true, sub2_listBox, sub1_listBox);
}
private void sub1_delete_from_db_btn_Click(object sender, EventArgs e)
{
Delete_Substance_From_DB(sub1_listBox,
sub2_listBox,sub2_list_is_from_file,sub1_delete_from_db_btn,
sub2_delete_from_db_btn);
}
private void sub2_delete_from_db_btn_Click(object sender, EventArgs e)
{
Delete_Substance_From_DB(sub2_listBox,
sub1_listBox,sub1_list_is_from_file,sub2_delete_from_db_btn,
sub1_delete_from_db_btn);
}
例如:如果我想删除一种物质,我需要从两个列表中删除它并从其他列表中删除它,将选择更改为下一个物质等...