@teilzteilzteilzteilz

Что делать, если не работает switch/case при совмещении с элементами radioButton?

При создании системы тестирования столкнулся с проблемой. С помощью метода switch/case решил создать вопросы с выборами ответов, с помощью элементов "radioButton" (добавил 4 radioButton'a на 1 вопрос).

Когда начал отладку на проверку ошибок и начал делать checked на эти радиобаттоны - началось зацикливание. К примеру, если я нажму в одном вопросе на 1 радиобаттон, он так и будет до конца теста при переходе на другие case с вопросами стоять checked, а если я в другом вопросе вдруг нажму к примеру на 3й радиобаттон - он и при возврате на предыдущие case'ы будет мне 3й выдавать, хотя я ставил 1ый на предыдущих вопросах.

Что мне нужно сделать, чтобы этого "зацикливания" на какой-либо из радиобаттонов не было? Чтобы если я выбрал 1ый радиобаттон в 4м вопросе - он бы так и был checked на 4м вопросе или на 2м вопросе 2 радиобатон чекед. Я пытался обнулять радиобаттоны, но ничего не получилось.

namespace ProgrammName
{
    public partial class Form3 : Form
    {
        int n = 0;
        int[] answer;
        int correct = 0;
        public Form3()
        {
            InitializeComponent();
            answer = new int[19];
        }

        public void show(int n)
        {
            int n1 = n + 1;
            label1.Text = "Вопрос" + " " + n1;
            switch (n)
            {
                //Вопрос 1
                case 0:
                    pictureBox1.Image = new Bitmap(ProgrammName.Properties.Resources.t1);
                    label2.Text = "";
                    radioButton1.Text = "60 000";
                    radioButton2.Text = "20 000";
                    radioButton3.Text = "80 000";
                    if (radioButton3.Checked == true)
                    {
                        correct++;
                    }
                    radioButton4.Text = "70 000";
                    pictureBox1.Visible = true;
                    pictureBox2.Visible = false;
                    break;
                //Вопрос 2
                case 1:
                    label2.Text = "";
                    radioButton1.Text = "20";
                    radioButton2.Text = "8";
                    radioButton3.Text = "10";
                    radioButton4.Text = "5";
                    pictureBox1.Visible = false;
                    pictureBox2.Visible = false;
                    answer[n] = 1;
                    break;
                //Вопрос 3
                case 2:
                    label2.Text = "";
                    radioButton1.Text = "30";
                    radioButton2.Text = "3";
                    radioButton3.Text = "12";
                    radioButton4.Text = "6";
                    pictureBox1.Visible = false;
                    pictureBox2.Visible = false;
                    answer[n] = 3;
                    break;
                //Вопрос 4
                case 3:
                    pictureBox1.Image = new Bitmap(ProgrammName.Properties.Resources.t4);
                    label2.Text = "";
                    radioButton1.Text = "8";
                    radioButton2.Text = "13";
                    radioButton3.Text = "5";
                    radioButton4.Text = "2";
                    pictureBox1.Visible = false;
                    pictureBox2.Visible = false;
                    answer[n] = 2;
                    break;
                //Вопрос 5
                case 4:
                    pictureBox1.Image = new Bitmap(ProgrammName.Properties.Resources.t5);
                    label2.Text = "";
                    radioButton1.Text = "4й";
                    radioButton2.Text = "7й";
                    radioButton3.Text = "3й";
                    radioButton4.Text = "5й";
                    pictureBox1.Visible = true;
                    pictureBox2.Visible = false;
                    answer[n] = 2;
                    break;
                //Вопрос 6
                case 5:
                    pictureBox1.Image = new Bitmap(ProgrammName.Properties.Resources.t6);
                    pictureBox2.Image = new Bitmap(ProgrammName.Properties.Resourcest6_1);
                    label2.Text = "";
                    radioButton1.Text = "10";
                    radioButton2.Text = "5";
                    radioButton3.Text = "8";
                    radioButton4.Text = "20";
                    pictureBox1.Visible = true;
                    pictureBox2.Visible = true;
                    break;
                //Вопрос 7
                case 6:
                    label2.Text = "";
                    radioButton1.Text = "4";
                    radioButton2.Text = "2";
                    radioButton3.Text = "8";
                    radioButton4.Text = "6";
                    pictureBox1.Visible = false;
                    pictureBox2.Visible = false;
                    break;
                    
                //Вопрос 8
                case 7:
                    label2.Text = "";
                    radioButton1.Text = "21";
                    radioButton2.Text = "12";
                    radioButton3.Text = "14";
                    radioButton4.Text = "26";
                    pictureBox1.Visible = false;
                    pictureBox2.Visible = false;
                    break;
                //Вопрос 9
                case 8:
                    label2.Text = "";
                    radioButton1.Text = "2";
                    radioButton2.Text = "3";
                    radioButton3.Text = "8";
                    radioButton4.Text = "10";
                    pictureBox1.Visible = false;
                    pictureBox2.Visible = false;
                    break;
                //Вопрос 10
                case 9:
                    label2.Text = "";
                    radioButton1.Text = "50";
                    radioButton2.Text = "10";
                    radioButton3.Text = "20";
                    radioButton4.Text = "100";
                    pictureBox1.Visible = false;
                    break;
            }
        } 
        private void button1_Click(object sender, EventArgs e)
        {

            n++;
            if (n > 19) n = 19;
            show(n);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            n--;
            if (n < 0) n = 0;
            show(n);
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            answer[n] = 1;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            answer[n] = 2;
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            answer[n] = 3;
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            answer[n] = 4;
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            radioButton1.Checked = false;
            radioButton2.Checked = false;
            radioButton3.Checked = false;
            radioButton4.Checked = false;
        }
    }
}
  • Вопрос задан
  • 120 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы