用户控制按钮

本文关键字:按钮 控制 用户 | 更新日期: 2023-09-27 17:52:40

我想为我的crud按钮创建一个自定义控件。用户控件将具有以下代码:

 private void btnDelete_Click(object sender, EventArgs e)
    {      if (MessageBox.Show("Are you sure to Delete?", "Please Confirm", MessageBoxButtons.OKCancel) == DialogResult.OK)
    {
        DeleteClick(sender, e); // this will read the code from GUI delete button
        if (DeleteResult.Success) 
        {
            MessageBox.Show("This record is deleted successfully.");
        }
        else
        {
            MessageBox.Show("This record is deleted failed.");
        }
    }

}

我GUI

private void adminUserController_DeleteClick(object sender, EventArgs e)
{
    Repository.Delete(user);
}

问题:
1)传递DeleteResult布尔结果从GUI到用户控制的最好方法是什么?我如何创建一个事件的删除按钮,可以由UI挂钩?2)你认为是好的,如果我把我的错误记录器代码在用户控制按钮?

用户控制按钮

将adminUserController_DeleteClick中的调用替换为对新方法(foo)的调用

private DeleteResult foo(TypeOfUser user)
{
   return Repository.Delete(user);
}

和调用foo代替adminUserController_DeleteClick

foo将返回所需的结果