0

問題が発生し続けていますが、何が問題なのかわかりません。Microsoft Visual Studio でプログラムを作成する必要があります。ここで、radioButton1 は連続する数値の合計を求めるためのもので、radioButton2 は数値の階乗を求めるためのものです。

FOR ループ用、WHILE ループ用、DO-WHILE ループ用の 3 つのボタンがあります。私はFORボタンに取り組んでいます。

私がやろうとしているのは、選択を行ってからボタンの1つを押すことで、メッセージボックスでクリックされたループを使用して答えを見つけることです.

これは私がこれまでに得たものです:

private void button1_Click(object sender, System.EventArgs e)
{
  if ((radioButton1.Checked == true) && (radioButton2.Checked == false))
  {
    int sum = 0;
    int number = int.Parse(numericUpDown1.Value.ToString());
    for (int i = 1; i <= number; i++)
    {
      sum = sum + i;
      MessageBox.Show("The sum of the consecutive numbers leading up to " + number + " is " + sum + ".");
    }
    MessageBox.Show("The sum of the consecutive numbers leading up to " + number + " is " + sum + ".");
  }
  else if ((radioButton2.Checked == true) && (radioButton1.Checked == false))
  {
    int product = 1;
    int number = int.Parse(numericUpDown1.Value.ToString());
    for (int i = 1; i <= number; i++)
    {
      product *= i;
      MessageBox.Show("The factorial of the numbers leading up to " + number + " is " + product + ".");
    }
    MessageBox.Show("The factorial of the numbers leading up to " + number + " is " + product + ".");
  }
  else
  {
    MessageBox.Show("Invalid");
  }
}

私はこのメッセージを受け取り続けます:

「'Lab5' には 'radioButton2.CheckedChanged' の定義が含まれておらず、タイプ 'Lab5' の最初の引数を受け入れる拡張メソッド 'radioButton2.CheckChanged' が見つかりませんでした (using ディレクティブまたはアセンブリ参照がありませんか?)。 "

そして、正直なところ、それが何を意味するのかわかりません。

どんな助けでも大歓迎です。

radioButton2 が選択されたときに、radioButton1 のメッセージ ボックスをポップアップさせたくないという理由だけで、if-else ステートメントに保持したいと考えています。

4

2 に答える 2

1

誤ってそのラジオ ボタンにハンドラーを追加し (デザイナーでダブルクリックするなど)、削除した可能性があります。ソリューションが構築されているとき、その関数を探していますが、見つかりません。

radioButton2 コードの Lab5.Designer.cs を確認します。次のようになります。

 this.radioButton1.AutoSize = true;
 this.radioButton1.Location = new System.Drawing.Point(102, 162);
 this.radioButton1.Name = "radioButton1";
 this.radioButton1.Size = new System.Drawing.Size(85, 17);
 this.radioButton1.TabIndex = 1;
 this.radioButton1.TabStop = true;
 this.radioButton1.Text = "radioButton1";
 this.radioButton1.UseVisualStyleBackColor = true;
 this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged); /* THis is the offending line! */

その最後の行は、存在しないメソッドを参照するイベント ハンドラーを追加しようとしています。ここで削除することもできます。

また、プログラムのビルド時にコンパイル エラーをダブルクリックすると、IDE が問題の原因を突き止めます。

于 2013-04-05T00:35:11.460 に答える
0

宿題のようです。いずれにしても、CheckChanged イベントのラジオ ボタンのハンドラーを実装する必要があります。また、これらのラジオ ボタンをグループに入れると、いずれかをチェックすることができ、checkchanged イベントで functionMode などを入力する必要があります。たとえば、RadioButton1 がチェックされている場合、適用する式を含む変数を保存する必要があります。チェックされている他の式では、それを変更する必要があります。ボタン送信イベントでは、その変数を使用して現在のモードを確認し、その数式を適用します。

于 2013-04-05T00:37:56.857 に答える