更新 : 2007 年 11 月
Windows フォームの一連の RadioButton コントロールをプログラムで作成し、その Text プロパティを文字列配列の値に設定する例を次に示します。
使用例
private void button1_Click(object sender, System.EventArgs e)
{
string[] stringArray = new string[3];
stringArray[0] = "Yes";
stringArray[1] = "No";
stringArray[2] = "Maybe";
System.Windows.Forms.RadioButton[] radioButtons =
new System.Windows.Forms.RadioButton[3];
for (int i = 0; i < 3; ++i)
{
radioButtons[i] = new RadioButton();
radioButtons[i].Text = stringArray[i];
radioButtons[i].Location = new System.Drawing.Point(
10, 10 + i * 20);
this.Controls.Add(radioButtons[i]);
}
}
コードのコンパイル方法
この例には、次の項目が必要です。
- button1 という名前の Button コントロールのある Windows フォーム。button1 の Click イベント ハンドラに button1_Click を設定します。
参照
概念
ユーザー インターフェイスのデザイン (Visual C#)