Change text of various textboxes from various forms

Viewed 37

I have a winforms application with multiple forms. In these forms I have multiple custom textboxes which are identical to the original textbox control with two more properties, propA and propB.

The objective of my application is to read from a data stream and display the messages in the corresponding custom textbox, from whichever form.

How can I iterate through all the custom textboxes from all forms, checking against propA and propB?

Here is what I currently have:

For j = 0 To dt.Rows.Count - 1
        
       If dt.Rows(j)("propA") = Message.propA Then

                For Each _txtbox As CustomTextBox In FindControlRecursive(allCtrl, ActiveForm, GetType(CustomTextBox))

                    If _txtbox.propB = dt.Rows(j)("propB") AndAlso _txtbox.propA = Message.propA Then

                        'Do stuff to message

                        Invoke(Sub()

                                   Form2.CustomTextBox1.Text = Message.Data  ' <- textbox updates even if form is out of focus

                                   _txtbox.Text = Message.Data ' <- textbox only updates if it's form is focused

                               End Sub)

                    End If

                Next

            End If

        Next    

I have tried changing FindControlRecursive, which returns a list of controls, to a list with all the controls in my application with no success.

0 Answers
Related