1- Add 3 forms (form1,form2,form3) to a project, Add one button (button1) to form1
2- In form2, create Sub New as Below
4- In form1, in button1_click add this
5- The function of GetFormByStringWithParameter is as below (you can put it in form1,or module)
2- In form2, create Sub New as Below
Public Class Form2 Sub New(p1,p2,p3) ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. MsgBox(p1.ToString) End Sub
End Class
3- In form3, create Sub New as Below
Public Class Form3 Sub New(p1,p2) ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. MsgBox(p2.ToString) End Sub End Class
4- In form1, in button1_click add this
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x = GetFormByStringWithParameter("form2",{1,2,3}) x.Show Dim y = GetFormByStringWithParameter("form3",{22,33}) y.Show End Sub
5- The function of GetFormByStringWithParameter is as below (you can put it in form1,or module)
Function GetFormByStringWithParameter(ByVal form_name As String,byval form_parameter() As Object) As Form Dim FullTypeName = Application.ProductName & "." & form_name Dim FormInstanceType = Type.GetType(FullTypeName, True, True) Dim objForm = CType(Activator.CreateInstance(FormInstanceType,form_parameter),Form) Return objForm End Function
No comments:
Post a Comment