0

您好,我无法在我的测验中更改到下一个问题。

private void Form1_Load(object sender, EventArgs e)
    {


        Random random = new Random();
        int Month = random.Next(0);


        if (Month == 0)
        {
            radioButton1.Text = "January";
            radioButton2.Text = "April";
            radioButton3.Text = "August";
            SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\1. Enero – January.Wav");
            simpleSound.Play();
        }

        if (Month == 1)
        {
            radioButton1.Text = "July";
            radioButton2.Text = "December";
            radioButton3.Text = "February";
            SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\2. Febero – February.Wav");
            simpleSound.Play();
        }
        if (Month == 2)
        {
            radioButton1.Text = "May";
            radioButton2.Text = "September";
            radioButton3.Text = "March";
            SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\3. Marzo – March.Wav");
            simpleSound.Play();
        }
        if (Month == 3)
        {
            radioButton1.Text = "April";
            radioButton2.Text = "August";
            radioButton3.Text = "March";
            SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\4. Abril – April.Wav");
            simpleSound.Play();
        }
        if (Month == 4)
        {
            radioButton1.Text = "March";
            radioButton2.Text = "May";
            radioButton3.Text = "November";
            SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\5. Mayo – May.Wav");
            simpleSound.Play();
        }
        if (Month == 5)
        {
            radioButton1.Text = "July";
            radioButton2.Text = "June";
            radioButton3.Text = "February";
            SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\6. Junio – June.Wav");
            simpleSound.Play();
        }
static int i = 0;


 private void button1_Click(object sender, EventArgs e)
    {
        Random random = new Random();
        int Month = random.Next(0);

        if (Month == 0)

        if (radioButton1.Checked)
        {
            label1.Text = "Correct";
            radioButton2.Enabled = false;
            radioButton3.Enabled = false;
        }
        else if (radioButton2.Checked)
        {
            label1.Text = "Incorrect";
            radioButton1.Enabled = false;
            radioButton3.Enabled = false;
        }
        else if (radioButton3.Checked)
        {
            label1.Text = "Incorrect";
            radioButton1.Enabled = false;
            radioButton3.Enabled = false;
        }


        if (Month == 1)

            if (radioButton1.Checked)
            {
                label1.Text = "Incorrect";
                radioButton2.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton2.Checked)
            {
                label1.Text = "Incorrect";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton3.Checked)
            {
                label1.Text = "Correct";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }


        if (Month == 2)

            if (radioButton1.Checked)
            {
                label1.Text = "Incorrect";
                radioButton2.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton2.Checked)
            {
                label1.Text = "Incorrect";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton3.Checked)
            {
                label1.Text = "Correct";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }


        if (Month == 3)

            if (radioButton1.Checked)
            {
                label1.Text = "Correct";
                radioButton2.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton2.Checked)
            {
                label1.Text = "Incorrect";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton3.Checked)
            {
                label1.Text = "Incorrect";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }


        if (Month == 4)

            if (radioButton1.Checked)
            {
                label1.Text = "Incorrect";
                radioButton2.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton2.Checked)
            {
                label1.Text = "Correct";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton3.Checked)
            {
                label1.Text = "Incorrect";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }


        if (Month == 5)

            if (radioButton1.Checked)
            {
                label1.Text = "Incorrect";
                radioButton2.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton2.Checked)
            {
                label1.Text = "Correct";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }
            else if (radioButton3.Checked)
            {
                label1.Text = "Incorrect";
                radioButton1.Enabled = false;
                radioButton3.Enabled = false;
            }

private void button2_Click(object sender, EventArgs e)
    {

        radioButton1.text = Month[i];
        radioButton2.text = Month[i];
        radioButton3.text= Month[i];

        i = (i + 1) % 5;

    }

出现 3 个错误,说“'System.Windows.Form.RadioButton' 不包含'text' 的定义,并且找不到接受第一个参数类型'System.Windows.Forms.RadioButton' 的扩展方法'text'(是您缺少 using 指令或程序集引用)

我对此很陌生,并试图自学 C#,所以请耐心等待我,在此先感谢。

4

2 回答 2

2

Adding to Rodrigo's answer:

private void button2_Click(object sender, EventArgs e) {

    radioButton1.Text = Month[i];
    radioButton2.Text = Month[i];
    radioButton3.Text= Month[i];

    i = (i + 1) % 5;

}

Here you are trying to set the Text property (string) to and integer (Month).

Try:

private void button2_Click(object sender, EventArgs e) {

    radioButton1.Text = Month[i].ToString();
    radioButton2.Text = Month[i].ToString();
    radioButton3.Text= Month[i].ToString();

    i = (i + 1) % 5;

}

Also, each of those RadioButtons will have the same text (Month number). Not sure if that is intended.

Additionally, you should use if else or a switch statement instead of if blocks in this case when checking for the current month. Currently, if Month == 1, it will still be checked against 2, 3, 4, etc needlessly.

Finally, consider limiting the creation of random numbers to a specified range.

于 2013-02-08T02:59:44.730 回答
2

C# 区分大小写。您要查找的属性是文本,而不是文本。

private void button2_Click(object sender, EventArgs e) {

    radioButton1.Text = Month[i];
    radioButton2.Text = Month[i];
    radioButton3.Text= Month[i];

    i = (i + 1) % 5;

}
于 2013-02-08T02:57:09.177 回答