Ruslan,
It sounds like you just need to expose a property of the UserControl that
is accessible to the Winform so it can pass information in. Or, you can
overload the CTOR of the control so that you pass the arguments in to the
control. Of course, then you have to modify the InitializeComponent of the
parent Winform code to pass in the appropriate arguments.
Regarding the ability to open a form that exists in the Winforms project,
your best bet is to create an instance of the form you need from the
Winforms app, and then pass a reference to it into your UserControl via its
CTOR or a public property. Then your button can call .Show or whatever.
Another way to do it would be to use reflection. Here is a sample using
reflection where you pass the form name into a property of the UserControl.
In the button click, we use reflection to instantiate the form and show it.
Private strFormName As String
Public Property FormName() As String
Get
Return strFormName
End Get
Set(ByVal Value As String)
strFormName = Value
End Set
End Property
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _
Button1.Click
Dim parentType As Type
Dim parentAsy As [Assembly]
Dim frm As Form
Dim obj As Object
parentType = Me.Parent.GetType
parentAsy = parentType.Assembly
Try
obj = parentAsy.CreateInstance(parentAsy.GetName.Name & "." &
strFormName)
frm = CType(obj, Form)
frm.Show()
Catch exc As Exception
MsgBox(exc.Message)
End Try
End Sub
Hope this helps!
Sincerely,
Keith Fink
Microsoft Developer Support