怎样按字母顺序(ABCDEF)动态添加控件

考试系统中题库设计时,我想动态添加选项,顺序按ABCDEF这样,点击一下按钮添加A(radiobutton),再点击添加B,如此依次添加。本人比较菜,求达人写一个方法。

private void button1_Click(object sender, EventArgs e)
{
string[] radioButtonList = new string[] { "A", "B", "C", "D", "E", "F", "G" }; for (int i = ; i < radioButtonList.Length; i++)
{
if (this.Controls[radioButtonList[i]] == null)
{
RadioButton radioButton = new RadioButton();
radioButton.Name = radioButtonList[i];
radioButton.Text = radioButtonList[i];
radioButton.Width = ;
radioButton.Location = new Point(, + i * );
this.Controls.Add(radioButton);
break;
}
}
}

换一下方法,横向加radiobutton。

private void button1_Click(object sender, EventArgs e)
{
string[] radioButtonList = new string[] { "A", "B", "C", "D", "E", "F", "G" }; for (int i = ; i < radioButtonList.Length; i++)
{
if (this.Controls[radioButtonList[i]] == null)
{
RadioButton radioButton = new RadioButton();
radioButton.Name = radioButtonList[i];
radioButton.Text = radioButtonList[i];
radioButton.Width = ;
radioButton.Location = new Point( + i * , );
this.Controls.Add(radioButton);
break;
}
}
}
上一篇:Windows 10 专业版 长期服务版 激活


下一篇:oo第3次博客作业