errores en botones en tiempo de ejecucion
Publicado por alvatross (3 intervenciones) el 11/10/2006 10:59:03
hola, tengo el siguiente problema, al crear los botones en tiempo de ejecucion, y crear el evento click de los mismo, me es imposible poder capturar su .text o cualquier atributo en el metodo asociado, para poder capturar el text tuve que inventar un codigo medio brujo pero que no es solucion para mi pues encesito poder trabajar con el boton que seleccione, como cambiar color o text, miren mi codigo y agradeceria me pudiecen ayudar. muchisimas gracias. ( el codigo de creacion de los botones esta en un foreach pues obtiene datos de un dataset en otra clase)
....
..codigo anterior a foreach
...
foreach (string s in mydataset.ordenarmaquina(label2.Text))
{
Button nuevoboton = new Button();
nuevoboton.Name="boton" + s;
nuevoboton.Parent=this.tabPage1;
nuevoboton.Left=(100*i)-100;
nuevoboton.Text= s;
nuevoboton.Size=new System.Drawing.Size(100, 100);
nuevoboton.Click +=new System.EventHandler(cliktoggleboton);
nuevoboton.Show();
i++;
}
private void cliktoggleboton (object sender, EventArgs e)
{
MessageBox.Show(sender.ToString().Trim().Substring(34));
//MessageBox.Show(nuevoboton.Text);
}
....
..codigo anterior a foreach
...
foreach (string s in mydataset.ordenarmaquina(label2.Text))
{
Button nuevoboton = new Button();
nuevoboton.Name="boton" + s;
nuevoboton.Parent=this.tabPage1;
nuevoboton.Left=(100*i)-100;
nuevoboton.Text= s;
nuevoboton.Size=new System.Drawing.Size(100, 100);
nuevoboton.Click +=new System.EventHandler(cliktoggleboton);
nuevoboton.Show();
i++;
}
private void cliktoggleboton (object sender, EventArgs e)
{
MessageBox.Show(sender.ToString().Trim().Substring(34));
//MessageBox.Show(nuevoboton.Text);
}
Valora esta pregunta


0