Instantiating form to lock button

Asked

Viewed 236 times

0

I’m instantiating a form with a single textbox just to put the password to release the button action.

The button has the function of exporting the data contained in datagridview for a spreadsheet in Excel, I’m trying to do this way:

private void btnExportar_Click(object sender, EventArgs e)
        {
            formExportar form = new formExportar();
            form.ShowDialog();

            if (exportar.txtsenha.Text == "123")
            {
               //código para exportar arquivos para o excel
            }
            else
            {
                MetroFramework.MetroMessageBox.Show(this, "Senha incorreta", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
    }

In case the formExportar is the authentication form where I enter the password, I am instantiating it in the main form this way:

public partial class TelaInicio : MetroFramework.Forms.MetroForm
    {
        internal formExportar exportar = new formExportar();

    public TelaInicio(formExportar exportar)
    {
        InitializeComponent();
        this.exportar = exportar;
    }

But by the fact of the button OK that exists in the formExportar not being executed turns out to be no action taking.

I also tried to play all the export code on formExportar instead of leaving in the main form but this ends up causing an error by the fact that there is no DataSource in that form, I really don’t know how to proceed with this.

1 answer

1


Just create in btn to open the password request:

        DialogResult resultado = new DialogResult();
        Form1 f = new Form1();
        resultado = f.ShowDialog();
        if (resultado == DialogResult.OK)
            MessageBox.Show("ok");
        else
        {
            MessageBox.Show("erro");
        }

and in the export form add two buttons, being one to ok and the other to exit.

Button to try password:

        if(textBox1.Text == "123")
        this.DialogResult = DialogResult.OK;
        else
        {
        MessageBox.Show("Senha incorreta");
        }

What was created is similar to a messagebox.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.