ウィンドウフォームのforループを使用して多くのラジオボタンを作成しようとしています。私が直面している問題は、個々のラジオボタンごとに変数名を生成することです。当初は、各ラジオボタンに0001、0002などの異なる番号を追加する予定です。ただし、変数名が文字列ではないため、できません。なにか提案を?
2 に答える
2
配列を使用します。
RadioButton[] rb = new RadioButton[100];
for (int i = 0; i < 100; i++)
{
rb[i] = new RadioButton();
rb[i].Location = new Point(0, i * 20);
rb[i].Text = "Your text here";
groupBox1.Controls.Add(rb[i]);
//etc.
}
私はVC++を知らないので、これはC#ですが、おそらくそれはあなたを助けることができます。
于 2012-04-11T20:24:46.597 に答える
-1
これを試して :
var rb = new List<RadioButton>();
bool Satisfied = false; int location =0;
while (!Satisfied)
{
rb.Add(new RadioButton() { Location = new Point(0, location * 20), Text = location.ToString() });
location++;
Satisfied = rb.Count > 100 ? true : false;
}
foreach ( object r in rb)
{
this.Controls.Add((RadioButton)r);
}
于 2012-04-12T04:42:11.743 に答える