0

Em um formulário o usuário poderá escolher a quantidade de imagens que ele poderá por, para cada imagem devo criar um texbox para ele colocar o URL de cada imagem. Ele determinará essa quantidade através de um NumericUpDown, daí tenho que ler o valor dele e aplicar na função para criar a quantidade de textbox:

Tentei assim:

private void criaImg(TextBox[] txt,  int X, int Y, int qnt)
{
    int cont = 0;
    while (cont < qnt)
    {
        txt[cont] = new System.Windows.Forms.TextBox();
        txt[cont].Location = new System.Drawing.Point(X, Y + Y);
        txt[cont].Name = "img" + cont;
        txt[cont].Size = new System.Drawing.Size(100, 20);
        txt[cont].TabIndex = 1;
        cont++;
    }

}
private void qntImg_ValueChanged(object sender, EventArgs e)
{
    TextBox[] array = new TextBox[(int)qntImg.Value];
    criaImg(array, 20, 30, (int)qntImg.Value);

}

Talvez fosse mais simples colocar um botão de ADD e quando o usuário clicar lá ele cria um textbox mas não funciona, como faço isso?

1 Resposta 1

0

Você criou o TextBox, mas você não adicionou ele no form.

Veja um exemplo com um botão:

private void InitializeComponent()
{
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    //
    // button1
    //
    this.button1.Location = new System.Drawing.Point(13, 13);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(75, 23);
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.UseVisualStyleBackColor = true;
    //
    // Form1
    //
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292, 273);

    // Veja no seu código onde fica este método ou similar e faça também!
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false);
}

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .