Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I programmatically add controls to a form and ensure they are displayed?

The controls that I've try to add to my form at runtime don't show up. What's wrong?

Make sure you implemented and executed code similar to the InitializeComponent method that VS adds to your Windows Forms project for controls added during design time. Recall that InitializeComponent() is called from your Forms constructor to create the controls, size, position and show the controls, and finally add the controls to the form's Controls collection. So, your code at runtime should also implement these same steps. In particular, don't forget the this.Controls.AddRange call that adds your new controls to the form's Controls collection.

Contributed from George Shepherd's Windows Forms FAQ



Page view counter