I am creating a user control that uses a communication component. The communication component uses the serial port, so only one instance can exist in a project, typically on the main startup form.
When my user control is added to a form in design mode, I need my user control to find the communication component which can reside on any form in the project.
I can use the following to get the components on the form where the user control is added, but not the other forms in the project:
Me.Parent.Site.Container.Components
I've tried to use reflection, but have only been able to get the list of forms and the controls on the forms, but not the components:
Can someone tell me how to search (in design mode) all forms in a project for a specific component?Code:Dim MyAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly Dim MyTypes As Type() = MyAssembly.GetTypes For Each mType As Type In MyTypes If mType.BaseType Is GetType(Form) Then Dim mForm As Form = Activator.CreateInstance(mType) '*** This only gives me controls, not components For i1 As Integer = 0 To mForm.Controls.Count - 1 If mForm.Controls(i1).GetType Is GetType(DF1Comm) Then MsgBox("Found DF1") End If Next mType.InvokeMember("Dispose", Reflection.BindingFlags.InvokeMethod, Nothing, mForm, Nothing) End If Next




Reply With Quote