我有十个复选框和枚举。我想将此复选框绑定到枚举。问题是代码有很多一致性。
public partial class RightsSetForm : Form
{
public RightsEnum rights;
public int count = 1;
public RightsSetForm()
{
InitializeComponent();
rights |= RightsEnum.notify;
}
private void chkNotify_CheckedChanged(object sender, EventArgs e)
{
if (chkNotify.Checked)
{
rights |= RightsEnum.notify;
count++;
}
else
{
rights ^= RightsEnum.notify;
count--;
}
}
private void chkFriends_CheckedChanged(object sender, EventArgs e)
{
if (chkFriends.Checked)
{
count++;
rights |= RightsEnum.friends;
}
else
{
rights ^= RightsEnum.friends;
count--;
}
}
}
是否可以简化?