user controls

  • Thread starter Thread starter Alejandro González
  • Start date Start date
A

Alejandro González

Hi.
I have this problem.
I create a user control with a constructor with several parameters.
I also add the default constructor so I can add this control in desing time
to a form.

Why this isn't working?
(default constructor was called in InitializeComponent())
private void Form1_Load(object sender, System.EventArgs e){
this.userControl1 = new UserControl("use this parameter");
}

after this call to the alt constructor I can debug and check that everthing
is ok, but the form still shows the control with old values.

thanks
 
Maybe you should update userControl1 contained in the form.Controls.
Hope this works.

Sincerely,
simida

Alejandro González 写é“:
 
update, invalidate or refresh don't to the trick
the form still shows the old control

Maybe you should update userControl1 contained in the form.Controls.
Hope this works.

Sincerely,
simida

Alejandro González ??:
 
Alejandro González said:
Hi.
I have this problem.
I create a user control with a constructor with several parameters.
I also add the default constructor so I can add this control in desing time
to a form.

Why this isn't working?
(default constructor was called in InitializeComponent())
private void Form1_Load(object sender, System.EventArgs e){
this.userControl1 = new UserControl("use this parameter");
}

after this call to the alt constructor I can debug and check that everthing
is ok, but the form still shows the control with old values.

Are you constructing two controls? One in InitializeComponent, and another
in your Form1_Load handler?
 
Alejandro González said:
It's just one control.
but when I add it to the form in design view, VS creates a call to the
default controler in the InitializeComponent.
I want to call another constructor, that receives some parameters.

The form doesn't refresh the control after the call in the load method

Without all the code, I cannot be sure, but it indeed appears that you are
constructing two controls. The InitializeComponent method constructs the
first control using the default constructor. Then you are constructing a
second control in your Form_Load method. Once you call a constructor, you
cannot call another constructor on the same object--the object is already
created.

What you want to do is expose some properties that allow you to set the
desired parameters later in the Form_Load method.
 
i don't get it. why do you want to recreate your control on form load??
can't you just add appropriate properties instead of another constructor
and set them either at design time or during form load?
 
Back
Top