string str = "Server=localhost;User ID=root;Password=123456;Database=test;";
MySqlConnection con = new MySqlConnection(str);//实例化链接
con.Open();//开启连接
string strcmd = "select * from range_info";
MySqlCommand cmd = new MySqlCommand(strcmd, con);
MySqlDataReader reader = cmd.ExecuteReader();
try
{
while (reader.Read())
{
if (reader.HasRows)
{
CheckBoxEx c = new CheckBoxEx();
c.Font = new Font("微软雅黑",12,c.Font.Style);
c.ForeColor = System.Drawing.Color.White;
c.Text=reader.GetString(1);
c.Name = "chk" + i;
c.Location = new System.Drawing.Point(10, i * 25);
panel5.Controls.Add(c);
i++;
}
}
}
catch (Exception) { }
con.Close();//关闭连接
学生党求帮助
2 个解决方案
#1
panel的大小也要设置啊
#2
自己解决了 需要设置控件的自定义大小 c.Autosize=true;
#1
panel的大小也要设置啊
#2
自己解决了 需要设置控件的自定义大小 c.Autosize=true;