RE:crear formulario dinamicamente
Hice un pequeño ejemplo que conecta a una bd sql y obtiene el numero de elementos de la base de datos y deacuerdo a este numero crea los controles y su evento.
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection conectarbd = new SqlConnection())
{
int totalcontroles=-1;
conectarbd.ConnectionString = "data source=.;initial catalog=controles;integrated security=true";
conectarbd.Open();
SqlCommand comando = new SqlCommand("select nombre from tabcontrol", conectarbd);
SqlDataReader leer = comando.ExecuteReader();
while (leer.Read())
totalcontroles++;
int j = 2;
for (int i = 0; i <= totalcontroles; i++)
{
Button btn = new Button();
btn.Location=new Point(10,20*j);
btn.Text = i.ToString();
btn.Click += new EventHandler(btn_Click);
Controls.Add(btn);
j += 2;
}
}
}
void btn_Click(object sender, EventArgs e)
{
MessageBox.Show("Hola");
}