Child Controls
Unlike main and context menus, controls[8] dragged from the Toolbox onto the surface provided by the Designer are added to the form's Controls collection. You can use that collection yourself to add controls dynamically at run time (as I showed earlier in this chapter), or you can add arrays of controls the way the Designer-generated InitializeComponent does:
[8] Technically speaking, both MainMenu and ContextMenu are components, as are all the rest of the items that you can drag and drop from the Toolbox that show up on the tray along the bottom of the design surface. For a list of the standard WinForms components, see Appendix D: Standard WinForms Components and Controls.
void InitializeComponent() {
this.SuspendLayout(); // ...
Get Windows Forms Programming in C# now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.