RE: Passing a constructor parameter with Activator.CreateInstance

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Josh,

Thanks for your feedback.

For other inherited form, we can pass the arguments like this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim args(0) As Object
args(0) = New Object
args(0) = 2
Dim f As Form2 = CType(Activator.CreateInstance(GetType(Form2),
args), Form2)
f.Show()
End Sub

Public Class Form2
Inherits System.Windows.Forms.Form

Sub New(ByVal SearchID As Int32)
MessageBox.Show(SearchID.ToString())
End Sub
End Class

It works well on my side. Thanks
==================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

.


Quantcast