Home > Mobile >  WPF switch between 2 Check boxes
WPF switch between 2 Check boxes

Time:03-27

** I am trying to make an if statement to switch the checked box between each other Image of check boxes here is what I got so far:**


        private void offline_CheckedChanged(object sender, EventArgs e)
        {
            offline.Checked = true;
            if (bot.Checked == true)
            {
                bot.Checked = false;
            }
        }

        private void bot_CheckedChanged(object sender, EventArgs e)
        {
            bot.Checked = true;
            if (offline.Checked == true)
            {
                offline.Checked = false;
            }
        }

CodePudding user response:

If you want only one of them to be checked at a time, you could use the negated values:

private void offline_CheckedChanged(object sender, EventArgs e)
{
    bot.Checked = !offline.Checked;
}

private void bot_CheckedChanged(object sender, EventArgs e)
{
    offline.Checked = !bot.Checked;
}

Keep in mind that you'd have to change their initial values if you want this behavior from the start of the application

  • Related