0

プログラミング初心者の悩み… 私のプログラムで。

現在の体重を維持するために必要なカロリー数を計算して表示しています。私は次2のセットを持っています2 radioButtons: 1 つのセットは性別、男性または女性用で、もう 1 つのセットは活動率、アクティブまたは非アクティブ用です。

の 2 つの異なるセットでradioButtons、それぞれから 1 つを選択できるはずですが、一度に 1 つのラジオ ボタンしか選択されていません。2 つのラジオ ボタンのセットを別々に扱うようにプログラムに指示するにはどうすればよいですか?

4

2 に答える 2

0

ラジオ ボタンはグループで機能します。それらをコンテナとあなたの良いもので分けてください。

于 2013-03-17T16:50:49.223 に答える
0

GroupBoxes を使用して、ラジオボタンのセットをグループボックス内に配置し、他のセットを別のグループボックス内に配置する必要があります

このようにして、ラジオボタンのすべてのセットが他のセットから分離され、期待どおりに機能します

次のコードは、フォームを手動で作成する例にすぎません。デザイナーを使用すると、InitializeComponent メソッド内にこのコードと同等のコードが作成されます。2 つのラジオボタン セットが異なるコンテナー (グループボックス) の子であることに注意してください。

' A generic form
Dim f as Form = new Form()
f.Size = new Size(300, 500)

' Create a Group box
Dim b1 as GroupBox = new GroupBox()
b1.Text = "Gender"
b1.Location = new Point(0,0)

' Create two radiobutton for Gender
Dim r1 as RadioButton = new RadioButton()
r1.Text = "Male"
r1.Location = new Point(5,15)
Dim r2 As RadioButton = new RadioButton()
r2.Text = "Female"
r2.Location = new Point(5, 40)

' Add the two radiobuttons to the GroupBox control collection
b1.Controls.AddRange(new Control() {r1, r2})

' Repeat for the second set of radiobuttons
Dim b2 as GroupBox = new GroupBox()
b2.Text = "Activity Rate"
b2.Location = new Point(0,100)
Dim r3 As RadioButton = new RadioButton()
r3.Text = "Active"
r3.Location = new Point(5,15)
Dim r4 as RadioButton = new RadioButton()
r4.Text = "Inactive"
r4.Location = new Point(5,40)
b2.Controls.AddRange(new Control() {r3, r4})

' Finally add the GroupBoxes to the Form ControlsCollection
f.Controls.AddRange(new Control() {b1, b2})

f.ShowDialog()
于 2013-03-17T16:51:01.173 に答える