VB.NET reference sender form in a separate module

38 views Asked by At

I am trying to loop through each panel and control in each user form I have in my application so I wrote a subroutine to call upon initialization of each user form. The problem I have encountered is referencing the sender user form in a separate module. The code I have:

    Sub Configure_UI()

        For Each Control_Panel As Panel In sender.Controls.OfType(Of Panel) 'Loop through panels
            For Each control In Control_Panel.Controls
                Configure_Control(control)
            Next
        Next
    End Sub

The error that it gives says "Sender is not declared. It may be inaccessible due to its protection level.". SO I wonder how do I fix this. What I need is a dynamic solution where sender is the form.name.

Could someone, please, help me out please?

1

There are 1 answers

0
Eduards On

so the solution is as follows

    Sub Configure_UI(ByVal sender As Form)

        For Each Control_Panel As Panel In sender.Controls.OfType(Of Panel) 'Loop through panels
            For Each control In Control_Panel.Controls
                Configure_Control(control)
            Next
        Next
    End Sub

and the call to it from user form initialization is:

Configure_UI(me)

Any suggestions on optimizing the solution?