Dynamic Controls - VB.NET

Public Class Form1
Friend WithEvents AxSftBox2 As AxSftBoxLib40.AxSftBox
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click ' Create one SftBox control based on a designed control
' (named AxSftBoxDesigned) Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1)) Me.AxSftBox2 = New AxSftBoxLib40.AxSftBox CType(Me.AxSftBox2, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() Me.AxSftBox2.Location = New System.Drawing.Point(27, 27) Me.AxSftBox2.Name = "AxSftBox2" ' THIS IS IMPORTANT: We are using the properties as defined by AxSftBoxDesigned to create the dynamic control Me.AxSftBox2.OcxState = CType(resources.GetObject("AxSftBoxDesigned.OcxState"), System.Windows.Forms.AxHost.State) Me.AxSftBox2.Size = New System.Drawing.Size(249, 38) Me.AxSftBox2.Location = New Point(Me.AxSftBoxDesigned.Location.X + 40, Me.AxSftBoxDesigned.Location.Y + 40) Me.AxSftBox2.TabIndex = 0 Me.Controls.Add(Me.AxSftBox2) CType(Me.AxSftBox2, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub End Class