foreach(DataRow dr in dt.Rows)
{
CheckBox chkbox = new CheckBox();
chkbox.Text = dr["模块名称"].ToString();
gpboxBrow.Controls.Add(chkbox);
}
添加都是在groupbox的text的位置,每添加一个就不前面加的覆盖了,怎么设置groupbox的布局,比如说layout
5 个解决方案
#1
怎么没人啊
#2
设置chkbox.Location属性。
int y = 0;
foreach(DataRow dr in dt.Rows)
{
y += 30;
CheckBox chkbox = new CheckBox();
chkbox.Location = new Point(10,y);
chkbox.Text = dr["模块名称"].ToString();
gpboxBrow.Controls.Add(chkbox);
}
#3
在你的代码中添加这样的代码:
chkbox.Location = new System.Drawing.Point(349, 210);
chkbox.Size = new System.Drawing.Size(75, 23);
例如下面的代码:动态添加两个Button
private void button2_Click(object sender, EventArgs e)
{
// button1
//
Button btn = new Button();
btn.Location = new System.Drawing.Point(349, 210);
btn.Name = "button1";
btn.Size = new System.Drawing.Size(75, 23);
btn.TabIndex = 2;
btn.Text = "button1";
btn.UseVisualStyleBackColor = true;
this.Controls.Add(btn);
//
// button2
//
Button btn2 = new Button();
btn2.Location = new System.Drawing.Point(349, 240);
btn2.Name = "button2";
btn2.Size = new System.Drawing.Size(75, 23);
btn2.TabIndex = 3;
btn2.Text = "button2";
this.Controls.Add(btn2);
}
chkbox.Location = new System.Drawing.Point(349, 210);
chkbox.Size = new System.Drawing.Size(75, 23);
例如下面的代码:动态添加两个Button
private void button2_Click(object sender, EventArgs e)
{
// button1
//
Button btn = new Button();
btn.Location = new System.Drawing.Point(349, 210);
btn.Name = "button1";
btn.Size = new System.Drawing.Size(75, 23);
btn.TabIndex = 2;
btn.Text = "button1";
btn.UseVisualStyleBackColor = true;
this.Controls.Add(btn);
//
// button2
//
Button btn2 = new Button();
btn2.Location = new System.Drawing.Point(349, 240);
btn2.Name = "button2";
btn2.Size = new System.Drawing.Size(75, 23);
btn2.TabIndex = 3;
btn2.Text = "button2";
this.Controls.Add(btn2);
}
#4
设置每个checkBox的location是最容易最好做的
#5
一行满了这么换行呢
#1
怎么没人啊
#2
设置chkbox.Location属性。
int y = 0;
foreach(DataRow dr in dt.Rows)
{
y += 30;
CheckBox chkbox = new CheckBox();
chkbox.Location = new Point(10,y);
chkbox.Text = dr["模块名称"].ToString();
gpboxBrow.Controls.Add(chkbox);
}
#3
在你的代码中添加这样的代码:
chkbox.Location = new System.Drawing.Point(349, 210);
chkbox.Size = new System.Drawing.Size(75, 23);
例如下面的代码:动态添加两个Button
private void button2_Click(object sender, EventArgs e)
{
// button1
//
Button btn = new Button();
btn.Location = new System.Drawing.Point(349, 210);
btn.Name = "button1";
btn.Size = new System.Drawing.Size(75, 23);
btn.TabIndex = 2;
btn.Text = "button1";
btn.UseVisualStyleBackColor = true;
this.Controls.Add(btn);
//
// button2
//
Button btn2 = new Button();
btn2.Location = new System.Drawing.Point(349, 240);
btn2.Name = "button2";
btn2.Size = new System.Drawing.Size(75, 23);
btn2.TabIndex = 3;
btn2.Text = "button2";
this.Controls.Add(btn2);
}
chkbox.Location = new System.Drawing.Point(349, 210);
chkbox.Size = new System.Drawing.Size(75, 23);
例如下面的代码:动态添加两个Button
private void button2_Click(object sender, EventArgs e)
{
// button1
//
Button btn = new Button();
btn.Location = new System.Drawing.Point(349, 210);
btn.Name = "button1";
btn.Size = new System.Drawing.Size(75, 23);
btn.TabIndex = 2;
btn.Text = "button1";
btn.UseVisualStyleBackColor = true;
this.Controls.Add(btn);
//
// button2
//
Button btn2 = new Button();
btn2.Location = new System.Drawing.Point(349, 240);
btn2.Name = "button2";
btn2.Size = new System.Drawing.Size(75, 23);
btn2.TabIndex = 3;
btn2.Text = "button2";
this.Controls.Add(btn2);
}
#4
设置每个checkBox的location是最容易最好做的
#5
一行满了这么换行呢