O'Reilly logo

Windows Forms Programming in C# by Chris Sells

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required