pregunta corta 7

12/11/2003 - 10:17 por Josema | Informe spam
hola...

Tengo un array que dependiendo de un factor tiene mas
elementos o menos...
Me gustaria crear un formulario con tantos imput text type
como elementos tenga el array??

Podeis aconsejarme sobre cual es la mejor manera de
realizar esto??

Preferiblemente me gustaria hacer un control para despues
agregarlo a la barra de herramientas y despues hacer drag
and drop en un webform por ejemplo.

Gracias.
Josema.
 

Leer las respuestas

#1 Mario Ruiz
12/11/2003 - 12:50 | Informe spam
Creo que te funcionara

private System.Windows.Forms.Label []etiquetas=null;

private System.Windows.Forms.TextBox []textos=null;

#region Manejo campos

private void BorraCampos()

{

if (this.etiquetas!=null)

{

this.SuspendLayout();

for (int i=0;i<this.etiquetas.Length;i++)

{

this.Controls.Remove(this.etiquetas[i]);

this.Controls.Remove(this.textos[i]);

this.etiquetas[i]=null;

this.textos[i]=null;

}

this.etiquetas=null;

this.textos=null;

this.ResumeLayout(false);

}

}

public void CreaEntradas(string []labs,string []text)

{

this.BorraCampos();

this.etiquetas=new Label[labs.Length];

this.textos=new TextBox[labs.Length];

this.SuspendLayout();


for (int i=0;i<labs.Length;i++)

{

this.CreaLabel(i,labs[i]);

this.CreaTexto(i,text[i]);

}

this.ResumeLayout(false);



}

private void CreaTexto(int i,string text)

{

this.textos[i] = new System.Windows.Forms.TextBox();

this.textos[i].Location = new System.Drawing.Point(500, 24+20*i);

this.textos[i].Name = text;

this.textos[i].Size = new System.Drawing.Size(96, 16);

this.textos[i].TabIndex = 0;

this.textos[i].Text = text;

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.textos[i]});



}

private void CreaLabel(int i,string text)

{

this.etiquetas[i] = new System.Windows.Forms.Label();

this.etiquetas[i].Location = new System.Drawing.Point(280, 24+20*i);

this.etiquetas[i].Name = text;

this.etiquetas[i].Size = new System.Drawing.Size(200, 16);

this.etiquetas[i].TabIndex = 0;

this.etiquetas[i].Text = text;

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.etiquetas[i]});



}

public string[] getDatos()

{

string[] datos=new string[this.textos.Length];

for (int i=0;i<this.textos.Length;i++)

{

datos[i]=this.textos[i].Text;

if (datos[i].Length==0) datos[i]="0";

}

return datos;

}

#endregion








"Josema" escribió en el mensaje
news:0b7c01c3a8fd$daa08110$
hola...

Tengo un array que dependiendo de un factor tiene mas
elementos o menos...
Me gustaria crear un formulario con tantos imput text type
como elementos tenga el array??

Podeis aconsejarme sobre cual es la mejor manera de
realizar esto??

Preferiblemente me gustaria hacer un control para despues
agregarlo a la barra de herramientas y despues hacer drag
and drop en un webform por ejemplo.

Gracias.
Josema.

Preguntas similares