Is it possible to create individual events for the instances of a form in C #?

1

Let's say I have a customer registration form:

        var frmCadCli1 = new frmCadastroCliente();

And I just called this form:

        frmCadCli1.Show();

When I call this form, immediately before it is shown the Form_Load event is triggered.

I happen to want to run a Form_Load different for each instance of frmCadastroCliente , for example:

      private void btnConsulta_Click(object sender, EventArgs e)
      {
        var frmCadCli2 = new frmCadastroCliente();
      }

Corresponding form load:

        private void Form1_Load(object sender, EventArgs e)
        {
          label1.Text = "Cadastro de Clientes";

        }

Then:

      private void btnAltera_Click(object sender, EventArgs e)
      {
        var frmCadCli3 = new frmCadastroCliente();
      }

Corresponding form load:

        private void Form1_Load(object sender, EventArgs e)
        {
          label1.Text = "Alteração de Cadastro";

        }

The reason I would like to run a Form_Load different for each instance is that I would have different instances with different purposes using the same design .

In this way I could, for example, use this form as a customer registration screen, change registration, or even as a supplier register, just changing the form's properties in Form_Load

    
asked by anonymous 09.12.2015 / 20:29

1 answer

2

You have to pass as parameter yourself. Even why you will need to save the correct registry.

    public Form(string Tipo)
    {
        InitializeComponent();
    }

And pass on the call what you want:

  private void btnConsulta_Click(object sender, EventArgs e)
  {
    var frmCadCli2 = new frmCadastroCliente("Clientes");
  }

 private void btnAltera_Click(object sender, EventArgs e)
  {
    var frmCadCli3 = new frmCadastroCliente("Fornecedores");
  }
    
09.12.2015 / 21:52