Click to See Complete Forum and Search --> : Where to place the initialization code in VC++.net?


LarryChen
February 6th, 2006, 12:38 PM
Is it a constructor or a function called InitializeComponent? Also would you please explain why? Thank you very much!

darwen
February 6th, 2006, 11:38 PM
You put initialisation code for non-UI classes in the constructor.

You shouldn't be editing the InitializeComponent part of any control as this is VC++ generated : you'll more likely than not either muck up the designer view or lose your code the next time you edit the control.

If you're talking about a form you have the Load event, which I'd recommend. You can override the OnLoad virtual protected method in your derived form class and do your initialisation in there.

Darwen.