1 回答
TA贡献1858条经验 获得超8个赞
实现此目的的一种方法是将这些bool字段封装到一个表示程序状态的类中,以及一个计算属性,true如果所有其他字段都是 则返回该计算属性true。
例如:
class ProgramState
{
public bool UserAcceptedAgreement { get; set; }
public bool UserAcknowledgedLiability { get; set; }
public bool UserSubmittedSignature { get; set; }
public bool EverythingAccepted =>
UserSubmittedSignature &&
UserAcknowledgedLiability &&
UserSubmittedSignature;
}
然后,您可以在您的类中创建此类的实例Form,并通过按钮单击事件设置属性,并在方法中Verify检查它们在if语句中是否全部为 true:
public partial class Form1 : Form
{
private ProgramState programState = new ProgramState();
public Form1()
{
InitializeComponent();
}
private void btnAcceptAgreement_Click(object sender, EventArgs e)
{
programState.UserAcceptedAgreement = true;
}
private void btnAcceptLiability_Click(object sender, EventArgs e)
{
programState.UserAcknowledgedLiability = true;
}
private void btnSubmitSignature_Click(object sender, EventArgs e)
{
programState.UserSubmittedSignature = true;
}
public void verify()
{
if (programState.EverythingAccepted)
{
tabControl.SelectedIndex = 2;
}
else
{
MessageBox.Show("Enter parameters");
}
}
}
- 1 回答
- 0 关注
- 122 浏览
添加回答
举报