How do I programmatically add controls at run time?

To add a control to a Windows Form dynamically at runtime, instantiate the control and add it to the parent container (Form, Panel, TabPage, and so on) by calling the parent's Controls.Add() method.

For example, in C#:

TextBox txtName = new TextBox();
txtName.Location = new Point(25,25);
this.Controls.Add (txtName);

And in VB .NET

Dim txtName As New TextBox()
txtName.Location = New Point(25, 25)
Me.Controls.Add(txtName)

If you want to subsequently bind all the controls, you can call the form's BindAllControls() methods. This causes all business objects on the form to raise a Bind event which in turn causes all controls to bind to the business object's data. If you want to bind individual controls, you can call the form's BindControl() method.


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/21/05
Comment or report problem with topic