Yes you can do that using reflection, consider this example
**FORM1**
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As New Form2("mytextbox")
x.Show()
End Sub
**FORM2**
Dim _myx As String
Public Sub New(ByVal myx As String)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
_myx = myx
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim asm As System.Reflection.Assembly
Dim objForm As Object = asm.CreateInstance(asm.Get
Me.Controls.Add(objForm)
End Sub
Main Topics
Browse All Topics





by: jrschererPosted on 2005-09-09 at 21:02:21ID: 14854937
Hi pcthelp,
I think you are talking about Windows Apps.
Yes it is possible. You can add controls to any form or to most visible controls.
The basic method is:
Dim Ctl As Control = New Label ' I use label as an example
FormX.Controls.Add(Ctl)
If you want to add a control from within the currently active form then use:
Dim Ctl As Control = New Label
Me.Controls.Add(Ctl)
If the control to be added is created somewhere else as in your case, you can get it from there:
Public Overloads Sub Show(ByVal ctl As Label)
Me.Controls.Add(ctl)
ctl.Location = New Point(200, 300) ' here you can set properties
ctl.Size = New Size(200, 50)
ctl.Name = "NewControl" ' and so on
End Sub
By the way, you don't need to override the method Show. Use Overloads since you have a different signature.
I hope this helps, Jack.net