So I have this little task where I am trying to change a single bool if any of my checkboxes are turned on.
So I have a boolean
Boolean YourAllowedToWork = false;
And a set of checkboxes
private void 001_Click(object sender, EventArgs e)
{
if (001.Checked)
{
YourAllowedToWork = true;
}
else
{
YourAllowedToWork = false;
}
}
private void 002_Click(object sender, EventArgs e)
{
if (002.Checked)
{
YourAllowedToWork = true;
}
else
{
YourAllowedToWork = false;
}
}
private void 003_Click(object sender, EventArgs e)
{
if (003.Checked)
{
YourAllowedToWork = true;
}
else
{
YourAllowedToWork = false;
}
}
private void 004_Click(object sender, EventArgs e)
{
if (004.Checked)
{
YourAllowedToWork = true;
}
else
{
YourAllowedToWork = false;
}
}
private void 005_Click(object sender, EventArgs e)
{
if (005.Checked)
{
YourAllowedToWork = true;
}
else
{
YourAllowedToWork = false;
}
}
private void 006_Click(object sender, EventArgs e)
{
if (006.Checked)
{
YourAllowedToWork = true;
}
else
{
YourAllowedToWork = false;
}
}
and although I haven't tested it, this looks to me like it will cause issues with conflicting itself and is clearly not very efficient. I'm still pretty new to programming and only 6 days in to C#.
Could anyone show me a better way to accomplish the above? I would assume there is some way of putting all these checkboxes into a list and listening for a change on any of them then checking the list to see if any of the checkbox values are true, if they are true, change the single boolean to true!
Thank you
Aucun commentaire:
Enregistrer un commentaire