用户通过图片框和单选按钮输入

时间:2017-04-25 05:30:15

标签: c# windows-forms-designer

请耐心等待,因为这是我第一次在这里写一个问题。我正在为我的C#面向对象的编程类开发一个项目,我在创建处理用户输入所需的方法时遇到了麻烦。

我有一个带有6个pictureBoxes和6个RadioButtons的窗体。每个单选按钮都有一个值,用户必须选择图片框,然后选择一个相应的单选按钮。我目前正在私有方法中使用switch case来验证输入并保持数据匹配,直到所有的radioButtons都用完为止。我遇到的问题是if语句只允许图片1接受radiobutton1的值,而不是能够选择任何radiobutton并填充标签。

int RadPicked = 0;

private void RadioButtonSelection(int radPicked)
    {
        switch(radPicked)
        {
            case (1):

                if (RadPicked == 1 && guessButton1.Checked)
                {
                    guessLabel1.Text = guessButton1.Text;
                    guessButton1.Enabled = false;
                }
                else if (RadPicked == 1 && guessButton2.Checked)
                {
                    guessLabel1.Text = guessButton2.Text;
                    guessButton2.Enabled = false;
                }
                else if (RadPicked == 1 && guessButton3.Checked)
                {
                    guessLabel1.Text = guessButton3.Text;
                    guessButton3.Enabled = false;
                }
                else if (RadPicked == 1 && guessButton4.Checked)
                {
                    guessLabel1.Text = guessButton4.Text;
                    guessButton4.Enabled = false;
                }
                else if (RadPicked == 1 && guessButton5.Checked)
                {
                    guessLabel1.Text = guessButton5.Text;
                    guessButton5.Enabled = false;
                }
                else if (RadPicked == 1 && guessButton6.Checked)
                {
                    guessLabel1.Text = guessButton6.Text;
                    guessButton6.Enabled = false;
                }
                else if (RadPicked == 0)
                {
                    MessageBox.Show("Please select an image before selecting an answer.");
                }

                break;
            case (2):

                if (RadPicked == 2 && guessButton1.Checked)
                {
                    guess2Label.Text = guessButton1.Text;
                    guessButton1.Enabled = false;
                }
                else if (RadPicked == 2 && guessButton2.Checked)
                {
                    guess2Label.Text = guessButton2.Text;
                    guessButton2.Enabled = false;
                }
                else if (RadPicked == 2 && guessButton3.Checked)
                {
                    guess2Label.Text = guessButton3.Text;
                    guessButton3.Enabled = false;
                }
                else if (RadPicked == 2 && guessButton4.Checked)
                {
                    guess2Label.Text = guessButton4.Text;
                    guessButton4.Enabled = false;
                }
                else if (RadPicked == 2 && guessButton5.Checked)
                {
                    guess2Label.Text = guessButton5.Text;
                    guessButton5.Enabled = false;
                }
                else if (RadPicked == 2 && guessButton6.Checked)
                {
                    guess2Label.Text = guessButton6.Text;
                    guessButton6.Enabled = false;
                }
                else if (RadPicked == 0)
                {
                    MessageBox.Show("Please select an image before selecting an answer.");
                }
                break;
            case (3):
                if (RadPicked == 3 && guessButton1.Checked)
                {
                    guess3Label.Text = guessButton1.Text;
                    guessButton1.Enabled = false;
                }
                else if (RadPicked == 3 && guessButton2.Checked)
                {
                    guess3Label.Text = guessButton2.Text;
                    guessButton2.Enabled = false;
                }
                else if (RadPicked == 3 && guessButton3.Checked)
                {
                    guess3Label.Text = guessButton3.Text;
                    guessButton3.Enabled = false;
                }
                else if (RadPicked == 3 && guessButton4.Checked)
                {
                    guess3Label.Text = guessButton4.Text;
                    guessButton4.Enabled = false;
                }
                else if (RadPicked == 3 && guessButton5.Checked)
                {
                    guess3Label.Text = guessButton5.Text;
                    guessButton5.Enabled = false;
                }
                else if (RadPicked == 3 && guessButton6.Checked)
                {
                    guess3Label.Text = guessButton6.Text;
                    guessButton6.Enabled = false;
                }
                else if (RadPicked == 0)
                {
                    MessageBox.Show("Please select an image before selecting an answer.");
                }
                break;
            case (4):
                if (RadPicked == 4 && guessButton1.Checked)
                {
                    guess4Label.Text = guessButton1.Text;
                    guessButton1.Enabled = false;
                }
                else if (RadPicked == 4 && guessButton2.Checked)
                {
                    guess4Label.Text = guessButton2.Text;
                    guessButton2.Enabled = false;
                }
                else if (RadPicked == 4 && guessButton3.Checked)
                {
                    guess4Label.Text = guessButton3.Text;
                    guessButton3.Enabled = false;
                }
                else if (RadPicked == 4 && guessButton4.Checked)
                {
                    guess4Label.Text = guessButton4.Text;
                    guessButton4.Enabled = false;
                }
                else if (RadPicked == 4 && guessButton5.Checked)
                {
                    guess4Label.Text = guessButton5.Text;
                    guessButton5.Enabled = false;
                }
                else if (RadPicked == 4 && guessButton6.Checked)
                {
                    guess4Label.Text = guessButton6.Text;
                    guessButton6.Enabled = false;
                }
                else if (RadPicked == 0)
                {
                    MessageBox.Show("Please select an image before selecting an answer.");
                }
                break;
            case (5):
                if (RadPicked == 5 && guessButton1.Checked)
                {
                    guess5Label.Text = guessButton1.Text;
                    guessButton1.Enabled = false;
                }
                else if (RadPicked == 5 && guessButton2.Checked)
                {
                    guess5Label.Text = guessButton2.Text;
                    guessButton2.Enabled = false;
                }
                else if (RadPicked == 5 && guessButton3.Checked)
                {
                    guess5Label.Text = guessButton3.Text;
                    guessButton3.Enabled = false;
                }
                else if (RadPicked == 5 && guessButton4.Checked)
                {
                    guess5Label.Text = guessButton4.Text;
                    guessButton4.Enabled = false;
                }
                else if (RadPicked == 5 && guessButton5.Checked)
                {
                    guess5Label.Text = guessButton5.Text;
                    guessButton5.Enabled = false;
                }
                else if (RadPicked == 5 && guessButton6.Checked)
                {
                    guess5Label.Text = guessButton6.Text;
                    guessButton6.Enabled = false;
                }
                else if (RadPicked == 0)
                {
                    MessageBox.Show("Please select an image before selecting an answer.");
                }
                break;
            case (6):
                if (RadPicked == 6 && guessButton1.Checked)
                {
                    guess6Label.Text = guessButton1.Text;
                    guessButton1.Enabled = false;
                }
                else if (RadPicked == 6 && guessButton2.Checked)
                {
                    guess6Label.Text = guessButton2.Text;
                    guessButton2.Enabled = false;
                }
                else if (RadPicked == 6 && guessButton3.Checked)
                {
                    guess6Label.Text = guessButton3.Text;
                    guessButton3.Enabled = false;
                }
                else if (RadPicked == 6 && guessButton4.Checked)
                {
                    guess6Label.Text = guessButton4.Text;
                    guessButton4.Enabled = false;
                }
                else if (RadPicked == 6 && guessButton5.Checked)
                {
                    guess6Label.Text = guessButton5.Text;
                    guessButton5.Enabled = false;
                }
                else if (RadPicked == 6 && guessButton6.Checked)
                {
                    guess6Label.Text = guessButton6.Text;
                    guessButton6.Enabled = false;
                }
                else if (RadPicked == 0)
                {
                    MessageBox.Show("Please select an image before selecting an answer.");
                }
                break;
        }
    }

    private void AnswerSelection(int picked)
    {
        switch (picked)
        {
            case (1):
                RadPicked = 1;

                break;
            case (2):
                RadPicked = 2;

                break;
            case (3):
                RadPicked = 3;

                break;
            case (4):
                RadPicked = 4;

                break;
            case (5):
                RadPicked = 5;

                break;
            case (6):
                RadPicked = 6;

                break;
        }
    }

    private void box1PictureBox_Click(object sender, EventArgs e)
    {
        AnswerSelection(1);
    }

    private void box2PictureBox_Click(object sender, EventArgs e)
    {
        AnswerSelection(2);
    }

    private void box3PictureBox_Click(object sender, EventArgs e)
    {
        AnswerSelection(3);
    }

    private void box4PictureBox_Click(object sender, EventArgs e)
    {
        AnswerSelection(4);
    }

    private void box5PictureBox_Click(object sender, EventArgs e)
    {
        AnswerSelection(5);
    }

    private void box6PictureBox_Click(object sender, EventArgs e)
    {
        AnswerSelection(6);
    }

    private void guessButton1_CheckedChanged(object sender, EventArgs e)
    {
        RadioButtonSelection(1);
    }

    private void guessButton2_CheckedChanged(object sender, EventArgs e)
    {
        RadioButtonSelection(2);
    }

    private void guessButton3_CheckedChanged(object sender, EventArgs e)
    {
        RadioButtonSelection(3);
    }

    private void guessButton4_CheckedChanged(object sender, EventArgs e)
    {
        RadioButtonSelection(4);
    }

    private void guessButton5_CheckedChanged(object sender, EventArgs e)
    {
        RadioButtonSelection(5);
    }

    private void guessButton6_CheckedChanged(object sender, EventArgs e)
    {
        RadioButtonSelection(6);
    }

感谢任何有时间看这个并帮助我的人。 @ 3:53 AM EST编辑以显示新的主要工作代码。

0 个答案:

没有答案