Load event in user control

  • Thread starter Thread starter mamil
  • Start date Start date
M

mamil

Hi Gurus.

I'm doing my first steps in the Winforms realm (I dealt mainly with
ASP.NET until now), and I've stumbled across issue I really cannot
solve and that seems extremely stupid to even ask about, so please
forgive me...

I need to execute some logic in the Load event of the control. Problem
is - I can't find that event for user controls! This logic cannot be
executed in the control's constructor, because its properties are not
set yet. I don't want to modify the InitializeComponent method code, as
I understand it is strongly un-recommened.

In ASP.NET, there is a Load event for every control, which enables me
to do just that. What is its equivalent in Winforms controls?

Thanks!
 
Hi Gurus.

I'm doing my first steps in the Winforms realm (I dealt mainly with
ASP.NET until now), and I've stumbled across issue I really cannot
solve and that seems extremely stupid to even ask about, so please
forgive me...

I need to execute some logic in the Load event of the control. Problem
is - I can't find that event for user controls! This logic cannot be
executed in the control's constructor, because its properties are not
set yet. I don't want to modify the InitializeComponent method code,
as I understand it is strongly un-recommened.

In ASP.NET, there is a Load event for every control, which enables me
to do just that. What is its equivalent in Winforms controls?

Thanks!

A control based on UserControl does have a load event, is your control
based on UserControl or another type of control?
 
My control inherits from the ComboBox control.
Is there any difference between regular UserControl and inherited
control?
 
(e-mail address removed) wrote: >> Problem is - I can't find that event for user
controls !

You could create a UserControl, then, in its load event, create an instance of
your over-ridden combobox, set its dockstyle to 'fill.

In a similar situation (a compound control inheriting from Label) I used the
following code to make sure I called the code that built the run-time "ui" only
when in run-time mode : whether this can be adapted to function in exactly the
way you want ?

// Override 'CreateControl to avoid design-time errors :
// build the UI only when we are NOT in design mode
protected override void OnCreateControl()
{
base.OnCreateControl();
if(this.Site == null)
{
CreateUI();
}
}

best, Bill Woodruff
dotScience
Chiang Mai, Thailand
 
Back
Top