working with controls on multiple forms

I have the following routine that searces for a control and removes it from a tabpage.
However, I also have need to pass the form, but if I use something like frm.tab, I obviously get an error that tab's not a member of frm.

So, the first part of my question is how can I accomplish this.
The latter part, which is probably going to be answered the same way is - how can I move this to a module?  I have a custom class where I need access to the same sub - I'd rather have only one instance instead of dropping a second in the other class...
Private Sub DestroyControl(ByVal strName As String, ByVal tab As TabPage)
        Dim ctl() As Control = tab.Controls.Find(strName, True)
        If ctl.Length > 0 Then
            ctl(0).Visible = False
            tab.Controls.Remove(ctl(0))
        End If
        ctl = Nothing
    End Sub

Open in new window

LVL 67
sirbountyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SanclerCommented:
You need to add another layer in to the find control sequence.  Following your present approach, you could have a sub something like this

    Public Sub DestroyControl(ByVal frm As Form, ByVal strName As String, ByVal tabpagename As String)
        Dim tab As TabPage
        Dim thetab() As Control = frm.Controls.Find(tabpagename, True)
        If thetab.Length > 0 Then
            tab = thetab(0)
            Dim ctl() As Control = tab.Controls.Find(strName, True)
            If ctl.Length > 0 Then
                ctl(0).Visible = False
                tab.Controls.Remove(ctl(0))
            End If
            ctl = Nothing
        End If
        tab = Nothing
    End Sub

I've made that Public, rather than private, so even if the code is on form1 you could call it from any other form.  But - picking up on your module question - you could put it in a module or class.  I've added a Form argument.  And I've changed the tab argument to a String - giving the name of the tabpage.  But, as I say, I've basically just followed your approach and added an "extra layer".  For real life purposes you'll probably want to tart it up or streamline it.  But it illustrates the approach.

Roger
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyAuthor Commented:
Hmm - tart it up...interesting suggestion...heh heh.
Thanx Roger - I was hoping you would come to my aid once again.  I'll try this out first thing in the morning. :^)
0
sirbountyAuthor Commented:
Perfect - thanx as always! :^)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.