1
Suppose I have a customer registration form:
var frmCadCli1 = new frmCadastroCliente();
And I just called that form:
frmCadCli1.Show();
When I call this form, immediately before it is shown the event Form_Load
is triggered.
I happen to want to execute one 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";
}
Afterward:
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’d like to execute a Form_Load
different for every instance is that I would have different instances with different purposes using the same design.
This way I could, for example, use the said form as a customer registration screen, change of registration, or even as a supplier registration, just changing the properties of the form on Form_Load
Why not pass a parameter in the constructor and validate it? Then you use only one
Form_Load()
calling several different methods.– Jéf Bueno
You say the same form load code running each time you open a new instance, right?
– Ricardo
@Ricardo is actually exact the opposite, a different form load for each instance.
– Ezequiel Barbosa