Add N items to a Textbox based on a NumericUpDown

2

I created a program that generates passwords , but only generates one at a time.

What I wanted was to be able to make a NumericUpDown available so that the user could choose how many passwords , which would then be displayed in Textbox .

How can I do this?

The code for my button is this:

    
asked by anonymous 16.04.2015 / 16:11

1 answer

2

You can do this as follows:

// No clique de um botão, ou num outro evento que queira
private void button1_Click(object sender, System.EventArgs e)
{
    // Remove as passwords que existirem na ListBox (caso as deseja manter remova a linha seguinte.
    listBox1.Items.Clear();

    // Loop ate ao numero seleccionado no numericupdown 
    for (int i = 0; i < numericUpDown1.Value; ++i)
    {
        // A cada iteraccao gere uma password nova
        var password = //seu código de gerar passwords;

        // Por fim adicione a nova password a ListBox.
        listBox1.Items.Add(password);
    }
}

The end result will be (using GUIDs as passwords ):

Edit:

Given your specific case:

if(...)
{
}
else
{
    CopyButton.Enabled = true;
    SaveButton.Enabled = true;

    // Modifique aqui para o seguinte codigo
    listBox1.Items.Clear();

    // Loop ate ao numero seleccionado no numericupdown 
    for (int i = 0; i < numericUpDown1.Value; ++i)
    {
        // A cada iteraccao gere uma password nova
        var password = Generator.GetRandomPassword(Convert.ToInt32(PasswordLengthList.Value), GetStringTemplate());

        // Por fim adicione a nova password a ListBox.
        listBox1.Items.Add(password);
    }
}

The way you are currently printing the generated password to textbox . You must add a listbox and use the above code.

    
19.04.2015 / 12:26