Form Lifetime
Although the user can't see a form until either Show or ShowDialog is called, a form exists as soon as the object is created. A new form object wakes up in the object's constructor, which the runtime calls when an object is first created. It's during the constructor that InitializeComponent is called and therefore when all the child controls are created and initialized.
It's a bad idea to put custom code into the InitializeComponent function because the Designer is likely to throw it away. However, if you'd like to add other controls or change anything set by the InitializeComponent method, you can do that in the constructor. If the initial form implementation was generated by one of the VS.NET wizards, you'll even have a helpful ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access