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 つのエラーが発生します。 using ディレクティブまたはアセンブリ参照がありません)

私はこれが初めてで、自分自身にc#を教えようとしているので、しばらくお待ちください。よろしくお願いします。

4

2 に答える 2

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 に答える
2

ロドリゴの答えに追加:

private void button2_Click(object sender, EventArgs e) {

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

    i = (i + 1) % 5;

}

ここでは、Textプロパティ (文字列) を整数 (月) に設定しようとしています。

試す:

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;

}

また、これらの各 RadioButton には同じテキスト (月番号) が含まれます。それが意図されているかどうかはわかりません。

さらに、この場合、現在の月を確認するときに、ブロックの代わりにif elseorswitchステートメントを使用する必要があります。if現在、 ifMonth == 1の場合、不必要に 2、3、4 などに対してチェックされます。

最後に、乱数の作成を指定された範囲に制限することを検討してください。

于 2013-02-08T02:59:44.730 に答える