一个项目中用到的实例,根据数据库查询出待显示的radioButton的个数,显示在一个新的窗口中。
//动态显示radioButton
public void showRadioButton(int listSize,List<String> list) {
//控件上边缘与容器上边缘的距离
int top = 6;
//记录循环,控件左上角相对于容器左上角的坐标
int i = 0;
int n = 0;
RadioButton[] radioButton = new RadioButton[listSize];
for (n = 0; n < listSize; n++)
{
if (n % 15 == 0 && n != 0)
{
i++;
if (i % 5 == 0)
{
top = 6 * n;
i = 0;
}
else
{
top = 6;
}
}
radioButton[n] = new RadioButton();
radioButton[n].AutoSize = true;
radioButton[n].Top = top;
//控件左上角相对于容器左上角的坐标,以及每个控件之间的距离
radioButton[n].Location = new Point(i * 150 + 2, top);
// MessageBox.Show(name[n].ToString());
radioButton[n].Text = list[n].ToString();
radioButton[n].Visible = true;
radioButton[n].Name = "radioButton" + n;
this.panel1.Controls.Add(radioButton[n]);
top = top + 21;
}
}
本文介绍了一个在项目中使用的实例,该实例能够根据数据库查询结果动态显示指定数量的RadioButton控件,并将其布局在一个新的窗口中。通过调整控件的位置和大小,确保了控件的合理分布。
4487

被折叠的 条评论
为什么被折叠?



